summaryrefslogtreecommitdiff
authorwimpie <wimpie>2005-01-04 01:44:52 (UTC)
committer wimpie <wimpie>2005-01-04 01:44:52 (UTC)
commit9a134ab03890d942d53b4121e31e2d37859fa42c (patch) (unidiff)
treee9db8bfc0734d96409c90e12712dd6d8204aeb21
parentb65cbb7c8b45d57f849722d22f8f165cc202ceb5 (diff)
downloadopie-9a134ab03890d942d53b4121e31e2d37859fa42c.zip
opie-9a134ab03890d942d53b4121e31e2d37859fa42c.tar.gz
opie-9a134ab03890d942d53b4121e31e2d37859fa42c.tar.bz2
New bluetooth library OT2 (loosely based on kbluetooth)
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/settings/networksettings2/opietooth2/OTManageGUI.ui198
-rw-r--r--noncore/settings/networksettings2/opietooth2/OTPairingGUI.ui158
-rw-r--r--noncore/settings/networksettings2/opietooth2/OTPeer.cpp366
-rw-r--r--noncore/settings/networksettings2/opietooth2/OTPeer.h135
-rw-r--r--noncore/settings/networksettings2/opietooth2/OTSDPAttribute.cpp329
-rw-r--r--noncore/settings/networksettings2/opietooth2/OTSDPAttribute.h140
-rw-r--r--noncore/settings/networksettings2/opietooth2/OTSDPService.cpp189
-rw-r--r--noncore/settings/networksettings2/opietooth2/OTSDPService.h75
-rw-r--r--noncore/settings/networksettings2/opietooth2/OTScanGUI.ui387
-rw-r--r--noncore/settings/networksettings2/opietooth2/OTUUID.cpp162
-rw-r--r--noncore/settings/networksettings2/opietooth2/OTUUID.h58
-rw-r--r--noncore/settings/networksettings2/opietooth2/Opietooth.cpp1003
-rw-r--r--noncore/settings/networksettings2/opietooth2/Opietooth.h194
-rw-r--r--noncore/settings/networksettings2/opietooth2/bluezlib.h28
-rw-r--r--noncore/settings/networksettings2/opietooth2/config.in5
-rw-r--r--noncore/settings/networksettings2/opietooth2/libopietooth2.control9
-rwxr-xr-xnoncore/settings/networksettings2/opietooth2/libopietooth2.postinst10
-rw-r--r--noncore/settings/networksettings2/opietooth2/opietooth2.pro37
18 files changed, 3483 insertions, 0 deletions
diff --git a/noncore/settings/networksettings2/opietooth2/OTManageGUI.ui b/noncore/settings/networksettings2/opietooth2/OTManageGUI.ui
new file mode 100644
index 0000000..6f4db07
--- a/dev/null
+++ b/noncore/settings/networksettings2/opietooth2/OTManageGUI.ui
@@ -0,0 +1,198 @@
1<!DOCTYPE UI><UI>
2<class>OTManageGUI</class>
3<widget>
4 <class>QWidget</class>
5 <property stdset="1">
6 <name>name</name>
7 <cstring>OTManageGUI</cstring>
8 </property>
9 <property stdset="1">
10 <name>geometry</name>
11 <rect>
12 <x>0</x>
13 <y>0</y>
14 <width>203</width>
15 <height>390</height>
16 </rect>
17 </property>
18 <property stdset="1">
19 <name>caption</name>
20 <string>Manage local devices</string>
21 </property>
22 <property>
23 <name>layoutMargin</name>
24 </property>
25 <property>
26 <name>layoutSpacing</name>
27 </property>
28 <vbox>
29 <property stdset="1">
30 <name>margin</name>
31 <number>0</number>
32 </property>
33 <property stdset="1">
34 <name>spacing</name>
35 <number>3</number>
36 </property>
37 <widget>
38 <class>QListView</class>
39 <column>
40 <property>
41 <name>text</name>
42 <string>Device</string>
43 </property>
44 <property>
45 <name>clickable</name>
46 <bool>true</bool>
47 </property>
48 <property>
49 <name>resizeable</name>
50 <bool>true</bool>
51 </property>
52 </column>
53 <column>
54 <property>
55 <name>text</name>
56 <string>New Column</string>
57 </property>
58 <property>
59 <name>clickable</name>
60 <bool>true</bool>
61 </property>
62 <property>
63 <name>resizeable</name>
64 <bool>true</bool>
65 </property>
66 </column>
67 <property stdset="1">
68 <name>name</name>
69 <cstring>AllDrivers_LV</cstring>
70 </property>
71 <property stdset="1">
72 <name>allColumnsShowFocus</name>
73 <bool>true</bool>
74 </property>
75 <property stdset="1">
76 <name>rootIsDecorated</name>
77 <bool>true</bool>
78 </property>
79 </widget>
80 <widget>
81 <class>QLayoutWidget</class>
82 <property stdset="1">
83 <name>name</name>
84 <cstring>Layout11</cstring>
85 </property>
86 <hbox>
87 <property stdset="1">
88 <name>margin</name>
89 <number>0</number>
90 </property>
91 <property stdset="1">
92 <name>spacing</name>
93 <number>6</number>
94 </property>
95 <widget>
96 <class>QCheckBox</class>
97 <property stdset="1">
98 <name>name</name>
99 <cstring>DriverIsUp_CB</cstring>
100 </property>
101 <property stdset="1">
102 <name>sizePolicy</name>
103 <sizepolicy>
104 <hsizetype>7</hsizetype>
105 <vsizetype>0</vsizetype>
106 </sizepolicy>
107 </property>
108 <property stdset="1">
109 <name>text</name>
110 <string>Is Up</string>
111 </property>
112 </widget>
113 <widget>
114 <class>QLabel</class>
115 <property stdset="1">
116 <name>name</name>
117 <cstring>TextLabel3</cstring>
118 </property>
119 <property stdset="1">
120 <name>sizePolicy</name>
121 <sizepolicy>
122 <hsizetype>1</hsizetype>
123 <vsizetype>1</vsizetype>
124 </sizepolicy>
125 </property>
126 <property stdset="1">
127 <name>text</name>
128 <string>Auto refresh</string>
129 </property>
130 </widget>
131 <widget>
132 <class>QSpinBox</class>
133 <property stdset="1">
134 <name>name</name>
135 <cstring>RefreshTimer_SB</cstring>
136 </property>
137 <property stdset="1">
138 <name>maximumSize</name>
139 <size>
140 <width>60</width>
141 <height>32767</height>
142 </size>
143 </property>
144 <property stdset="1">
145 <name>margin</name>
146 <number>0</number>
147 </property>
148 <property stdset="1">
149 <name>suffix</name>
150 <string>s</string>
151 </property>
152 <property stdset="1">
153 <name>specialValueText</name>
154 <string>Default</string>
155 </property>
156 <property stdset="1">
157 <name>buttonSymbols</name>
158 <enum>PlusMinus</enum>
159 </property>
160 <property stdset="1">
161 <name>maxValue</name>
162 <number>10</number>
163 </property>
164 </widget>
165 </hbox>
166 </widget>
167 </vbox>
168</widget>
169<connections>
170 <connection>
171 <sender>DriverIsUp_CB</sender>
172 <signal>toggled(bool)</signal>
173 <receiver>OTManageGUI</receiver>
174 <slot>SLOT_UpDriver( bool)</slot>
175 </connection>
176 <connection>
177 <sender>RefreshTimer_SB</sender>
178 <signal>valueChanged(int)</signal>
179 <receiver>OTManageGUI</receiver>
180 <slot>SLOT_SetRefreshTimer( int )</slot>
181 </connection>
182 <connection>
183 <sender>AllDrivers_LV</sender>
184 <signal>currentChanged(QListViewItem*)</signal>
185 <receiver>OTManageGUI</receiver>
186 <slot>SLOT_ShowDriver( QListViewItem *)</slot>
187 </connection>
188 <connection>
189 <sender>AllDrivers_LV</sender>
190 <signal>clicked(QListViewItem*)</signal>
191 <receiver>OTManageGUI</receiver>
192 <slot>SLOT_ShowDriver( QListViewItem *)</slot>
193 </connection>
194 <slot access="public">SLOT_SetRefreshTimer( int )</slot>
195 <slot access="public">SLOT_ShowDriver( QListViewItem *)</slot>
196 <slot access="public">SLOT_UpDriver( bool)</slot>
197</connections>
198</UI>
diff --git a/noncore/settings/networksettings2/opietooth2/OTPairingGUI.ui b/noncore/settings/networksettings2/opietooth2/OTPairingGUI.ui
new file mode 100644
index 0000000..2a010f0
--- a/dev/null
+++ b/noncore/settings/networksettings2/opietooth2/OTPairingGUI.ui
@@ -0,0 +1,158 @@
1<!DOCTYPE UI><UI>
2<class>OTPairingGUI</class>
3<widget>
4 <class>QWidget</class>
5 <property stdset="1">
6 <name>name</name>
7 <cstring>OTPairingGUI</cstring>
8 </property>
9 <property stdset="1">
10 <name>geometry</name>
11 <rect>
12 <x>0</x>
13 <y>0</y>
14 <width>285</width>
15 <height>230</height>
16 </rect>
17 </property>
18 <property stdset="1">
19 <name>caption</name>
20 <string>Manage pairing</string>
21 </property>
22 <property>
23 <name>layoutMargin</name>
24 </property>
25 <property>
26 <name>layoutSpacing</name>
27 </property>
28 <vbox>
29 <property stdset="1">
30 <name>margin</name>
31 <number>3</number>
32 </property>
33 <property stdset="1">
34 <name>spacing</name>
35 <number>3</number>
36 </property>
37 <widget>
38 <class>QListView</class>
39 <column>
40 <property>
41 <name>text</name>
42 <string>From</string>
43 </property>
44 <property>
45 <name>clickable</name>
46 <bool>true</bool>
47 </property>
48 <property>
49 <name>resizeable</name>
50 <bool>true</bool>
51 </property>
52 </column>
53 <column>
54 <property>
55 <name>text</name>
56 <string>To</string>
57 </property>
58 <property>
59 <name>clickable</name>
60 <bool>true</bool>
61 </property>
62 <property>
63 <name>resizeable</name>
64 <bool>true</bool>
65 </property>
66 </column>
67 <property stdset="1">
68 <name>name</name>
69 <cstring>Pairs_LV</cstring>
70 </property>
71 <property stdset="1">
72 <name>allColumnsShowFocus</name>
73 <bool>true</bool>
74 </property>
75 <property stdset="1">
76 <name>showSortIndicator</name>
77 <bool>false</bool>
78 </property>
79 <property stdset="1">
80 <name>rootIsDecorated</name>
81 <bool>true</bool>
82 </property>
83 </widget>
84 <widget>
85 <class>QLayoutWidget</class>
86 <property stdset="1">
87 <name>name</name>
88 <cstring>Layout5</cstring>
89 </property>
90 <hbox>
91 <property stdset="1">
92 <name>margin</name>
93 <number>0</number>
94 </property>
95 <property stdset="1">
96 <name>spacing</name>
97 <number>6</number>
98 </property>
99 <spacer>
100 <property>
101 <name>name</name>
102 <cstring>Spacer1</cstring>
103 </property>
104 <property stdset="1">
105 <name>orientation</name>
106 <enum>Horizontal</enum>
107 </property>
108 <property stdset="1">
109 <name>sizeType</name>
110 <enum>Expanding</enum>
111 </property>
112 <property>
113 <name>sizeHint</name>
114 <size>
115 <width>20</width>
116 <height>20</height>
117 </size>
118 </property>
119 </spacer>
120 <widget>
121 <class>QLabel</class>
122 <property stdset="1">
123 <name>name</name>
124 <cstring>Unpair_LBL</cstring>
125 </property>
126 <property stdset="1">
127 <name>text</name>
128 <string>Disable Bluetooth to break pairings</string>
129 </property>
130 </widget>
131 <widget>
132 <class>QPushButton</class>
133 <property stdset="1">
134 <name>name</name>
135 <cstring>Unpair_But</cstring>
136 </property>
137 <property stdset="1">
138 <name>text</name>
139 <string>Break</string>
140 </property>
141 </widget>
142 </hbox>
143 </widget>
144 </vbox>
145</widget>
146<connections>
147 <connection>
148 <sender>Unpair_But</sender>
149 <signal>clicked()</signal>
150 <receiver>OTPairingGUI</receiver>
151 <slot>SLOT_Unpair()</slot>
152 </connection>
153 <slot access="public">SLOT_SetRefreshTimer( int )</slot>
154 <slot access="public">SLOT_ShowDriver( QListViewItem *)</slot>
155 <slot access="public">SLOT_UpDriver( bool)</slot>
156 <slot access="public">SLOT_Unpair()</slot>
157</connections>
158</UI>
diff --git a/noncore/settings/networksettings2/opietooth2/OTPeer.cpp b/noncore/settings/networksettings2/opietooth2/OTPeer.cpp
new file mode 100644
index 0000000..0d7e943
--- a/dev/null
+++ b/noncore/settings/networksettings2/opietooth2/OTPeer.cpp
@@ -0,0 +1,366 @@
1//-*-c++-*-
2/***************************************************************************
3 * Copyright (C) 2003 by Fred Schaettgen *
4 * kdebluetooth@schaettgen.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 ***************************************************************************/
11
12#include <assert.h>
13#include <sys/poll.h>
14#include <string.h>
15
16#include <bluezlib.h>
17#include <qarray.h>
18#include <qtextstream.h>
19
20#include <opie2/odebug.h>
21
22#include <OTDeviceAddress.h>
23#include <OTSDPAttribute.h>
24#include <OTSDPService.h>
25#include <OTPeer.h>
26#include <OTGateway.h>
27#include <OTDriver.h>
28
29using namespace Opietooth2;
30
31OTPeer::OTPeer( OTGateway * _OT ) {
32 OT = _OT;
33 State = Peer_Unknown;
34 ConnectedTo = 0;
35}
36
37OTPeer::OTPeer( QTextStream & TS, OTGateway * _OT ) {
38 OT = _OT;
39 State = Peer_Unknown;
40 ConnectedTo = 0;
41
42 load( TS );
43}
44
45OTPeer::~OTPeer( ) {
46
47}
48
49void OTPeer::updateServices( void ) {
50 sdp_session_t *session;
51
52 serviceList.clear();
53
54 owarn << "Get services from " << Addr.toString() << oendl;
55
56 session = sdp_connect( &(OTDeviceAddress::any.getBDAddr()),
57 &(Addr.getBDAddr()),
58 0);
59
60 if (!session) {
61 owarn << "sdp_connect("
62 << Addr.toString()
63 << ") failed"
64 << oendl;
65 return; // error
66 }
67
68 uint32_t range = 0x0000ffff;
69 sdp_list_t* attrId = sdp_list_append(0, &range);
70
71 // search all public features
72 uuid_t grp;
73 sdp_uuid16_create( &grp, PUBLIC_BROWSE_GROUP );
74 sdp_list_t * search = sdp_list_append(0, &grp );
75
76 // get data from peer
77 sdp_list_t* seq;
78 if (sdp_service_search_attr_req( session,
79 search,
80 SDP_ATTR_REQ_RANGE,
81 attrId,
82 &seq ) ) {
83 owarn << "Service Search failed" << oendl;
84 sdp_close(session);
85 return;
86 }
87
88 sdp_list_free(attrId, 0);
89 sdp_list_free(search, 0);
90
91 // process result
92 sdp_list_t* next = NULL;
93
94 for (; seq; seq = next) {
95 sdp_record_t *rec = (sdp_record_t *) seq->data;
96
97 sdp_list_t* attrlist = rec->attrlist;
98 AttributeVector alist;
99 OTSDPService * service;
100
101 service = new OTSDPService();
102
103 for (; attrlist; attrlist = attrlist->next) {
104 int attrID = ((sdp_data_t*)(attrlist->data))->attrId;
105 service->addAttribute(
106 attrID,
107 new OTSDPAttribute( (sdp_data_t*)(attrlist->data) )
108 );
109 }
110
111 serviceList.resize( serviceList.size() + 1 );
112 serviceList.insert( serviceList.size() - 1, service );
113
114 next = seq->next;
115 free(seq);
116 sdp_record_free(rec);
117 }
118 sdp_close(session);
119}
120
121bool OTPeer::hasServiceClassID( const OTUUID & uuid) {
122 for( unsigned int i = 0;
123 i < serviceList.count();
124 i ++ ) {
125 if( serviceList[i]->hasClassID(uuid))
126 return true;
127 }
128 return false;
129}
130/** Get a vector of Rfcomm channels of the services having "uuid" in the class ID List*/
131QArray<int> OTPeer::rfcommList( const OTUUID & uuid) {
132
133 QArray<int> rfcommList;
134 unsigned int channel;
135
136 for( unsigned int i = 0;
137 i < serviceList.count();
138 i ++ ) {
139 if( serviceList[i]->hasClassID(uuid)) {
140 if( serviceList[i]->rfcommChannel(channel) ) {
141 rfcommList.resize( rfcommList.size()+1 );
142 rfcommList[rfcommList.size()-1] = channel;
143 }
144 }
145 }
146 return rfcommList;
147}
148
149void OTPeer::save( QTextStream & TS ) {
150 TS << "bdaddr " << address().toString() << endl;
151 TS << "name " << name() << endl;
152 TS << "class " << deviceClass() << endl;
153}
154
155void OTPeer::load( QTextStream & TS ) {
156 QString S;
157 S = TS.readLine();
158 setAddress( OTDeviceAddress( S.mid( 7 ) ) );
159
160 S = TS.readLine();
161 setName( S.mid( 5 ) );
162
163 S = TS.readLine();
164 setDeviceClass( S.mid( 6 ).toLong() );
165}
166
167#define MAGICNR -99999
168#define POLLDELAY 1000
169#define PREMAGICNR (MAGICNR+POLLDELAY)
170
171void OTPeer::findOutState( int timeoutInSec, bool Force ) {
172 ProbeFD = -1;
173 if( Force && ConnectedTo == 0 ) {
174 State = OTPeer::Peer_Unknown;
175 } // else keep state or is connected to us
176
177 if( State == OTPeer::Peer_Unknown ) {
178 ProbePhase = 0;
179 ProbeTimeout = timeoutInSec*1000;
180 owarn << "Ping " << address().toString() << oendl;
181 startTimer( POLLDELAY );
182 } else {
183 ProbeTimeout = 0;
184 startTimer( 0 );
185 }
186}
187
188#define PINGSIZE 20
189void OTPeer::timerEvent( QTimerEvent * ev ) {
190
191 ProbeTimeout -= POLLDELAY;
192
193 if( State == OTPeer::Peer_Unknown ) {
194 switch( ProbePhase ) {
195 case 0 : // connect nonblock
196 { struct sockaddr_l2 addr;
197
198 if (( ProbeFD = ::socket(PF_BLUETOOTH, SOCK_RAW, BTPROTO_L2CAP)) < 0) {
199 ProbeTimeout = 0;
200 break;
201 }
202
203 memset(&addr, 0, sizeof(addr));
204
205 addr.l2_family = AF_BLUETOOTH;
206 addr.l2_bdaddr = OTDeviceAddress::any.getBDAddr();
207
208 if( ::bind( ProbeFD, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
209 ProbeTimeout = 0;
210 break;
211 }
212
213 // non blocking
214 if( ::fcntl( ProbeFD, F_SETFL, O_NONBLOCK ) < 0 ) {
215 ProbeTimeout = 0;
216 break;
217 }
218
219 // to this peer
220 addr.l2_bdaddr = address().getBDAddr();
221 if( ::connect( ProbeFD, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
222 if( errno != EAGAIN && errno != EINPROGRESS ) {
223 ProbeTimeout = 0;
224 break;
225 } // wait for connect to fail or succeed
226 }
227 }
228 ProbePhase = 1; // wait for connect
229 break;
230 case 1 :
231 { struct pollfd pf[1];
232 char buf[L2CAP_CMD_HDR_SIZE + PINGSIZE + 20];
233 int n;
234
235 pf[0].fd = ProbeFD;
236 pf[0].events = POLLOUT;
237 if( (n = ::poll(pf, 1, 0)) < 0 ) {
238 owarn << address().toString()
239 << " : errno "
240 << errno
241 << " "
242 << strerror(errno)<<oendl;
243 ProbeTimeout = 0;
244 break;
245 }
246
247 if( ! n ) {
248 // not ready -> try again
249 break;
250 }
251
252 // send ping
253 for( unsigned int i = L2CAP_CMD_HDR_SIZE; i < sizeof(buf); i++)
254 buf[i] = (i % 40) + 'A';
255
256 l2cap_cmd_hdr *cmd = (l2cap_cmd_hdr *) buf;
257
258 /* Build command header */
259 cmd->code = L2CAP_ECHO_REQ;
260 cmd->ident = *(char *)this; // get some byte
261 cmd->len = PINGSIZE;
262
263 /* Send Echo Request */
264 if( ::send(ProbeFD, buf, PINGSIZE + L2CAP_CMD_HDR_SIZE, 0) <= 0) {
265 if( errno == EACCES ) {
266 // permission denied means that we could not
267 // connect because the device does not allow us
268 // but it is UP
269 owarn << address().toString()
270 << " good send error "
271 << errno
272 << " "
273 << strerror( errno)
274 << oendl;
275 State = OTPeer::Peer_Up;
276 ProbeTimeout = 0;
277 break;
278 } else if( errno != EBUSY ) {
279 owarn << address().toString()
280 << " : errno "
281 << errno
282 << " "
283 << strerror(errno)
284 << oendl;
285 ProbeTimeout = 0;
286 break;
287 } // else want some more
288 }
289
290 ProbePhase = 2; // wait for ping reply
291 }
292 break;
293 case 2 : // wait for reply
294 { struct pollfd pf[1];
295 char buf[L2CAP_CMD_HDR_SIZE + PINGSIZE + 20];
296 l2cap_cmd_hdr *cmd = (l2cap_cmd_hdr *) buf;
297 int n;
298
299 pf[0].fd = ProbeFD;
300 pf[0].events = POLLIN;
301 if( (n = ::poll(pf, 1, 0)) < 0 ) {
302 owarn << address().toString()
303 << " : errno "
304 << errno
305 << " "
306 << strerror(errno)
307 <<oendl;
308 ProbeTimeout = 0;
309 break;
310 }
311
312 if( ! n ) {
313 // not ready -> try again
314 break;
315 }
316
317 if( (n = ::recv( ProbeFD, buf, sizeof(buf), 0)) < 0) {
318 owarn << address().toString()
319 << "errno "
320 << errno
321 << " "
322 << strerror(errno)
323 << oendl;
324 ProbeTimeout = 0;
325 break;
326 }
327
328 /* Check for our id */
329 if( cmd->ident != *(char *)this )
330 // not our reply
331 break;
332
333 owarn << "reply from "
334 << address().toString()
335 << oendl;
336 // whatever reply we get is a valid reply
337 State = OTPeer::Peer_Up;
338 ProbeTimeout = 0;
339 }
340 break;
341 }
342
343 if( State != OTPeer::Peer_Unknown ) {
344 ProbeTimeout = 0;
345 }
346 }
347
348 if( ProbeTimeout <= 0 ) {
349 // regular timeout
350 emit peerStateReport( this );
351 if( State == Peer_Unknown ) {
352 State = Peer_Down;
353 }
354 if( ProbeFD >= 0 ) {
355 // requested to stop by caller -> stop probing
356 ::close( ProbeFD );
357 }
358 // no more waiting
359 killTimer( ev->timerId() );
360 } // else sleep some more
361}
362
363void OTPeer::stopFindingOutState( void ) {
364 ProbeTimeout = PREMAGICNR;
365}
366
diff --git a/noncore/settings/networksettings2/opietooth2/OTPeer.h b/noncore/settings/networksettings2/opietooth2/OTPeer.h
new file mode 100644
index 0000000..c09af15
--- a/dev/null
+++ b/noncore/settings/networksettings2/opietooth2/OTPeer.h
@@ -0,0 +1,135 @@
1//-*-c++-*-
2/***************************************************************************
3 * Copyright (C) 2003 by Fred Schaettgen *
4 * kdebluetooth@0xF.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 ***************************************************************************/
11
12#ifndef OTPEER_H
13#define OTPEER_H
14
15#include <qstring.h>
16#include <qobject.h>
17#include <qvector.h>
18#include <bluezlib.h>
19#include <OTDeviceAddress.h>
20
21class QTextStream;
22class QTimerEvent;
23
24namespace Opietooth2 {
25
26class OTGateway;
27
28class OTDriver;
29class OTSDPService;
30class OTSDPAttribute;
31class OTUUID;
32typedef QVector<OTSDPService> ServiceVector;
33
34class OTPeer : public QObject {
35
36 Q_OBJECT;
37
38public :
39
40 typedef enum PeerState_E {
41 Peer_Unknown = -1,
42 Peer_Down = 0,
43 Peer_Up = 1
44 } PeerState_t;
45
46 OTPeer( OTGateway * _OT );
47 OTPeer( QTextStream & TS, OTGateway * _TS );
48 ~OTPeer();
49
50 inline OTGateway * gateway() const
51 { return OT; }
52
53 inline int deviceClass( void ) const
54 { return Class; }
55 inline void setDeviceClass( int cls )
56 { Class = cls; }
57
58 void setAddress( const OTDeviceAddress & A )
59 { Addr = A; }
60
61 const OTDeviceAddress & address( void )
62 { return Addr; }
63
64 inline QString name( void ) const
65 { return Name; }
66 inline void setName( const QString & n )
67 { Name = n; }
68
69 ServiceVector & services( bool Force = 0 )
70 { if( Force || serviceList.count() == 0 ) {
71 updateServices();
72 }
73 return serviceList;
74 }
75
76 /* Returns TRUE if the device has at least a service
77 with inside the required class Id.*/
78 bool hasServiceClassID( const OTUUID & uuid);
79
80 /* Get a vector of Rfcomm channels of the services
81 having "uuid" in the class ID List */
82 QArray<int> rfcommList( const OTUUID & uuid );
83
84 inline void setState( PeerState_t S)
85 { State = S; }
86 inline PeerState_t state( void )
87 { return State; }
88
89 // go and find out state
90 // will report back with signal
91 void findOutState( int timeoutInSec = 1, bool Force = 0 );
92 void stopFindingOutState( void );
93
94 // return driver to which this peer is connected to
95 // if it is connected
96 inline OTDriver * connectedTo( void ) const
97 { return ConnectedTo; }
98 inline void setConnectedTo( OTDriver * D )
99 { ConnectedTo = D; }
100
101 void save( QTextStream& TS );
102 void load( QTextStream& TS );
103
104signals :
105
106 // report back state
107 void peerStateReport( OTPeer *);
108 void error( const QString & );
109
110protected :
111
112 // while polling for result of ping
113 void timerEvent( QTimerEvent * ev );
114
115private:
116
117 void updateServices();
118
119 OTGateway * OT;
120 OTDeviceAddress Addr;
121 QString Name;
122 int Class;
123 ServiceVector serviceList;
124 // -1 : don't know, 0 no, 1 yes
125 PeerState_t State;
126 OTDriver * ConnectedTo;
127
128 int ProbeFD;
129 int ProbePhase; // see OTDriver
130 long ProbeTimeout;
131};
132
133}
134
135#endif
diff --git a/noncore/settings/networksettings2/opietooth2/OTSDPAttribute.cpp b/noncore/settings/networksettings2/opietooth2/OTSDPAttribute.cpp
new file mode 100644
index 0000000..9069c09
--- a/dev/null
+++ b/noncore/settings/networksettings2/opietooth2/OTSDPAttribute.cpp
@@ -0,0 +1,329 @@
1//-*-c++-*-
2/***************************************************************************
3 * Copyright (C) 2003 by Fred Schaettgen *
4 * kdebluetooth@schaettgen.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 ***************************************************************************/
11
12#include <assert.h>
13#include <qregexp.h>
14#include <opie2/odebug.h>
15
16#include <OTUUID.h>
17#include <OTSDPAttribute.h>
18
19using namespace Opietooth2;
20
21OTSDPAttribute::OTSDPAttribute() {
22 type = INVALID;
23 memset( &Value, 0, sizeof( Value ) );
24}
25
26OTSDPAttribute::~OTSDPAttribute() {
27 if( type == INT ) {
28 delete Value.intVal;
29 } else if( type == UUID ) {
30 delete Value.uuidVal;
31 } else if( type == UINT ) {
32 delete Value.uintVal;
33 } else if( type == STRING ||
34 type == URL
35 ) {
36 delete Value.stringVal;
37 } else if( type == ALTERNATIVE ||
38 type == SEQUENCE
39 ) {
40 delete Value.sequenceVal;
41 }
42}
43
44OTSDPAttribute::OTSDPAttribute( sdp_data_t * attrib ) {
45 setNil();
46 switch( attrib->dtd ) {
47 case SDP_DATA_NIL: // Nil type
48 { setNil();
49 break;
50 }
51 case SDP_UINT8: // Unsigned integer
52 setUInt(attrib->val.uint8);
53 break;
54 case SDP_UINT16: // Unsigned integer
55 setUInt(attrib->val.uint16);
56 break;
57 case SDP_UINT32: // Unsigned integer
58 setUInt(attrib->val.uint32);
59 break;
60 case SDP_UINT64: // Unsigned integer
61 setUInt(attrib->val.uint64);
62 break;
63 case SDP_UINT128: // Unsigned integer
64 // setUInt(attrib->val.uint16);
65 assert(false); // BUG/TODO: uint128 integers not supported
66 break;
67 case SDP_INT8: // Unsigned integer
68 setInt(attrib->val.int8);
69 break;
70 case SDP_INT16: // Unsigned integer
71 setInt(attrib->val.int16);
72 break;
73 case SDP_INT32: // Unsigned integer
74 setInt(attrib->val.int32);
75 break;
76 case SDP_INT64: // Unsigned integer
77 setInt(attrib->val.int64);
78 break;
79 case SDP_INT128: // Unsigned integer
80 // newAttr.setInt(attrib->val.uint16);
81 assert(false); // BUG/TODO: uint128 integers not supported
82 break;
83 case SDP_UUID16:
84 { OTUUID id;
85 ::uuid_t uuidVal = attrib->val.uuid;
86 id.setUUID32(uuidVal.value.uuid16);
87 setUUID(id );
88 }
89 break;
90 case SDP_UUID32:
91 { OTUUID id;
92 ::uuid_t uuidVal = attrib->val.uuid;
93 id.setUUID32(uuidVal.value.uuid32);
94 setUUID(id );
95 }
96 break;
97 case SDP_UUID128:
98 { OTUUID id;
99 ::uuid_t uuidVal = attrib->val.uuid;
100 uint64_t* v128;
101 v128 = reinterpret_cast<uint64_t*>(&(uuidVal.value.uuid128));
102 id.setUUID128(v128[0], v128[1]);
103 setUUID(id );
104 }
105 break;
106 case SDP_TEXT_STR_UNSPEC :
107 case SDP_TEXT_STR8 :
108 case SDP_TEXT_STR16 :
109 case SDP_TEXT_STR32 :
110 setString( QString(attrib->val.str) );
111 break;
112 case SDP_URL_STR_UNSPEC :
113 case SDP_URL_STR8 :
114 case SDP_URL_STR16 :
115 case SDP_URL_STR32 :
116 setURL( QString(attrib->val.str) );
117 break;
118 case SDP_BOOL:
119 setBool( attrib->val.int8 != 0);
120 break;
121 case SDP_SEQ_UNSPEC :
122 case SDP_SEQ8 :
123 case SDP_SEQ16 :
124 case SDP_SEQ32 :
125 case SDP_ALT_UNSPEC :
126 case SDP_ALT8 :
127 case SDP_ALT16 :
128 case SDP_ALT32 :
129 { AttributeVector subAttribs;
130 OTSDPAttribute * Attr;
131 sdp_data_t* subAttrib = attrib->val.dataseq;
132
133 for (; subAttrib; subAttrib = subAttrib->next) {
134
135 Attr = new OTSDPAttribute(subAttrib);
136 subAttribs.resize( subAttribs.size() + 1 );
137 subAttribs.insert( subAttribs.size() - 1, Attr );
138 }
139
140 if( attrib->dtd == SDP_ALT_UNSPEC ||
141 attrib->dtd == SDP_ALT8 ||
142 attrib->dtd == SDP_ALT16 ||
143 attrib->dtd == SDP_ALT32 ) {
144 setAlternative(subAttribs);
145 } else {
146 setSequence(subAttribs);
147 }
148 break;
149 }
150 } // end case
151}
152
153QString OTSDPAttribute::toString( void ) {
154 QString S;
155 switch( type ) {
156 case INVALID :
157 S = "invalid";
158 break;
159 case NIL :
160 S = "NIL";
161 break;
162 case UINT :
163 S = Value.uintVal->toString();
164 break;
165 case INT :
166 S = Value.intVal->toString();
167 break;
168 case UUID :
169 S = Value.uuidVal->toString();
170 break;
171 case BOOLEAN :
172 S = (Value.boolVal) ? "true" : "false";
173 break;
174 case STRING :
175 S = *(Value.stringVal);
176 break;
177 case URL :
178 S = *(Value.stringVal);
179 break;
180 case SEQUENCE :
181 S.sprintf( "Sequence(%d)", Value.sequenceVal->count() );
182 break;
183 case ALTERNATIVE :
184 S.sprintf( "Alternative(%d)", Value.sequenceVal->count() );
185 break;
186 case UNKNOWN :
187 S = "unknown";
188 break;
189 }
190 return S;
191}
192
193void OTSDPAttribute::setNil() {
194 type = NIL;
195}
196
197void OTSDPAttribute::setInt(const OTSDPAttribute::int128_t & val) {
198 type = INT;
199 Value.intVal = new int128_t( val );
200}
201
202void OTSDPAttribute::setUInt(const uint128_t & val) {
203 type = UINT;
204 Value.uintVal = new uint128_t(val);
205}
206
207void OTSDPAttribute::setUUID(const OTUUID & val) {
208 type = UUID;
209 Value.uuidVal = new OTUUID( val );
210}
211
212void OTSDPAttribute::setBool(bool val) {
213 type = BOOLEAN;
214 Value.boolVal = val;
215}
216
217void OTSDPAttribute::setString( const QString & val) {
218 type = STRING;
219 Value.stringVal = new QString( val );
220}
221
222void OTSDPAttribute::setURL( const QString & val) {
223 type = URL;
224 Value.stringVal = new QString(val);
225}
226
227void OTSDPAttribute::setSequence(const AttributeVector& val) {
228 type = SEQUENCE;
229 Value.sequenceVal = new AttributeVector();
230 Value.sequenceVal->setAutoDelete( TRUE );
231 *Value.sequenceVal = val;
232}
233
234void OTSDPAttribute::setAlternative(const AttributeVector& val) {
235 type = ALTERNATIVE;
236 Value.sequenceVal = new AttributeVector();
237 Value.sequenceVal->setAutoDelete( TRUE );
238 *Value.sequenceVal = val;
239}
240
241QString OTSDPAttribute::getString() {
242 assert(type == STRING);
243 return *Value.stringVal;
244}
245
246QString OTSDPAttribute::getURL() {
247 assert(type == URL);
248 return *Value.stringVal;
249}
250
251const OTSDPAttribute::int128_t & OTSDPAttribute::getInt() {
252 assert(type == INT);
253 return *Value.intVal;
254}
255
256
257const OTSDPAttribute::uint128_t & OTSDPAttribute::getUInt() {
258 assert(type == UINT);
259 return *Value.uintVal;
260}
261
262const OTUUID & OTSDPAttribute::getUUID() {
263 assert(type == UUID);
264 return *Value.uuidVal;
265}
266
267bool OTSDPAttribute::getBool() {
268 assert(type == BOOLEAN);
269 return Value.boolVal;
270}
271
272AttributeVector * OTSDPAttribute::getSequence() {
273 assert(type == SEQUENCE);
274 return Value.sequenceVal;
275}
276
277AttributeVector * OTSDPAttribute::getAlternative() {
278 assert(type == ALTERNATIVE);
279 return Value.sequenceVal;
280}
281
282UUIDVector OTSDPAttribute::getAllUUIDs() {
283
284 UUIDVector uuids;
285
286 if (getType() == UUID) {
287 uuids.resize( uuids.size()+1 );
288 uuids[uuids.size()-1] = getUUID();
289 } else {
290 AttributeVector * subAttributes = 0 ;
291
292 if (getType() == SEQUENCE) {
293 subAttributes = getSequence();
294 } else if (getType() == ALTERNATIVE) {
295 subAttributes = getAlternative();
296 }
297
298 int os;
299 for( unsigned int i = 0; i < subAttributes->count(); i++ ) {
300 UUIDVector subUUIDs = (*subAttributes)[i]->getAllUUIDs();
301
302 os = uuids.size();
303 uuids.resize( uuids.size()+subUUIDs.count() );
304
305 for( unsigned int k = 0; k < subUUIDs.count(); k++ ) {
306 uuids[os + k] = subUUIDs[k];
307 }
308 }
309 }
310 return uuids;
311}
312
313static char * Attr2String[] = {
314 "Invalid",
315 "Nil",
316 "UInt",
317 "int",
318 "UUID",
319 "Boolean",
320 "String",
321 "Sequence",
322 "Alternative",
323 "URL",
324 "Unknown"
325};
326
327const char * OTSDPAttribute::getTypeString() {
328 return Attr2String[type];
329}
diff --git a/noncore/settings/networksettings2/opietooth2/OTSDPAttribute.h b/noncore/settings/networksettings2/opietooth2/OTSDPAttribute.h
new file mode 100644
index 0000000..e79e33d
--- a/dev/null
+++ b/noncore/settings/networksettings2/opietooth2/OTSDPAttribute.h
@@ -0,0 +1,140 @@
1//-*-c++-*-
2/***************************************************************************
3 * Copyright (C) 2003 by Fred Schaettgen *
4 * kdebluetooth@schaettgen.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 ***************************************************************************/
11
12#ifndef OTATTRIBUTE_H
13#define OTATTRIBUTE_H
14
15#include <stdio.h>
16#include <qstring.h>
17#include <qarray.h>
18#include <qvector.h>
19#include <bluezlib.h>
20#include <OTUUID.h>
21
22namespace Opietooth2 {
23
24class OTSDPAttribute;
25class OTUUID;
26
27typedef QVector<OTSDPAttribute> AttributeVector;
28
29/**
30@author Fred Schaettgen
31*/
32class OTSDPAttribute {
33
34public:
35
36 enum AttrType {
37 INVALID = 0,
38 NIL = 1,
39 UINT = 2,
40 INT = 3,
41 UUID = 4,
42 BOOLEAN = 5,
43 STRING = 6,
44 SEQUENCE = 7,
45 ALTERNATIVE = 8,
46 URL = 9,
47 UNKNOWN = 10
48 };
49
50 class int128_t {
51 public :
52 int128_t(int64_t l=0, int64_t h=0) {
53 hi = h;
54 lo = l;
55 }
56 int128_t(const OTSDPAttribute::int128_t & l) {
57 hi = l.hi;
58 lo = l.lo;
59 }
60 QString toString() const {
61 char Buf[50];
62 sprintf( Buf, "%lld%lld", hi, lo );
63 return QString( Buf );
64 }
65 int64_t hi;
66 int64_t lo;
67 };
68
69 class uint128_t {
70 public :
71 uint128_t( uint64_t l=0, uint64_t h=0) {
72 hi = h;
73 lo = l;
74 }
75 uint128_t( const OTSDPAttribute::uint128_t & l) {
76 hi = l.hi;
77 lo = l.lo;
78 }
79 QString toString() const {
80 char Buf[50];
81 sprintf( Buf, "%llu%llu", hi, lo );
82 return QString( Buf );
83 }
84 uint64_t hi;
85 uint64_t lo;
86 };
87
88public:
89
90 OTSDPAttribute();
91 OTSDPAttribute( sdp_data_t * D );
92 ~OTSDPAttribute();
93
94 QString toString( void );
95
96 void setNil();
97 void setInt(const OTSDPAttribute::int128_t & val);
98 void setUInt(const OTSDPAttribute::uint128_t & val);
99 void setUUID( const OTUUID & val);
100 void setBool(bool val);
101 void setString(const QString & val);
102 void setURL(const QString & val);
103 void setSequence(const AttributeVector& val);
104 void setAlternative(const AttributeVector& val);
105
106 QString getString();
107 QString getURL();
108 const OTSDPAttribute::int128_t & getInt();
109 const OTSDPAttribute::uint128_t & getUInt();
110 const OTUUID & getUUID();
111 bool getBool();
112 AttributeVector * getSequence();
113 AttributeVector * getAlternative();
114
115 UUIDVector getAllUUIDs();
116
117 inline AttrType getType()
118 { return type; }
119
120 //QString getValString();
121 const char * getTypeString();
122
123private:
124
125 AttrType type;
126
127 union {
128 OTSDPAttribute::int128_t * intVal;
129 OTSDPAttribute::uint128_t * uintVal;
130 OTUUID * uuidVal;
131 bool boolVal;
132 QString * stringVal; // strings and urls
133 AttributeVector * sequenceVal; // sequences and alternatives
134 } Value;
135
136};
137
138}
139
140#endif
diff --git a/noncore/settings/networksettings2/opietooth2/OTSDPService.cpp b/noncore/settings/networksettings2/opietooth2/OTSDPService.cpp
new file mode 100644
index 0000000..07b505c
--- a/dev/null
+++ b/noncore/settings/networksettings2/opietooth2/OTSDPService.cpp
@@ -0,0 +1,189 @@
1/***************************************************************************
2 * Copyright (C) 2003 by Fred Schaettgen *
3 * kdebluetooth@schaettgen.de *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 ***************************************************************************/
10
11#include <opie2/odebug.h>
12
13#include <OTSDPAttribute.h>
14#include <OTSDPService.h>
15
16using namespace Opietooth2;
17
18OTSDPService::OTSDPService() : attributeList() {
19}
20
21OTSDPService::~OTSDPService() {
22 for (unsigned int n=0; n < attributeList.count(); ++n) {
23 delete attributeList[n].attr;
24 }
25}
26
27void OTSDPService::addAttribute(int id, OTSDPAttribute * attr) {
28 attributeList.resize( attributeList.size() + 1 );
29
30 attributeList[attributeList.size() - 1].id = id;
31 attributeList[attributeList.size() - 1].attr = attr;
32}
33
34const OTSDPAttribute & OTSDPService::attribute(int index) {
35 return *(attributeList[index].attr);
36}
37
38int OTSDPService::attributeID(int index) {
39 return attributeList[index].id;
40
41}
42
43OTSDPAttribute * OTSDPService::attributeByID(int id) {
44
45 for (unsigned int n=0; n < attributeList.count(); ++n) {
46 if (attributeList[n].id == id) {
47 return attributeList[n].attr;
48 }
49 }
50 return 0;
51}
52
53bool OTSDPService::recordHandle(uint32_t *handle) {
54 OTSDPAttribute * attrib;
55 attrib = attributeByID(0x00);
56 if( attrib && attrib->getType() == OTSDPAttribute::UINT) {
57 *handle = (uint32_t)attrib->getUInt().lo;
58 return true;
59 }
60 return false;
61}
62
63QString OTSDPService::name(void) {
64 QString S;
65 OTSDPAttribute * attrib;
66 attrib = attributeByID(0x100);
67 if( attrib && attrib->getType() == OTSDPAttribute::STRING) {
68 S = attrib->getString();
69 }
70 return S;
71}
72
73QString OTSDPService::description() {
74 QString S;
75 OTSDPAttribute * attrib;
76 attrib = attributeByID(0x101);
77 if ( attrib && attrib->getType() == OTSDPAttribute::STRING) {
78 S = attrib->getString();
79 }
80 return S;
81}
82
83UUIDVector OTSDPService::allUUIDs() {
84 UUIDVector uuidList;
85
86 for ( unsigned int i = 0;
87 i < attributeList.count();
88 i ++ ) {
89 int os;
90 UUIDVector subList = attributeList[i].attr->getAllUUIDs();
91 os = uuidList.size();
92 uuidList.resize( uuidList.size()+subList.count() );
93
94 for( unsigned int k = 0; k < subList.count(); k++ ) {
95 uuidList[os + k] = subList[k];
96 }
97 }
98 return uuidList;
99}
100
101bool OTSDPService::rfcommChannel(unsigned int &n) {
102 // Get the rfcomm channel
103 OTSDPAttribute * protoDescAttr;
104 // Get the the protocol descriptor list attribute (0x04)
105 protoDescAttr = attributeByID(0x04);
106 if( ! protoDescAttr ) {
107 return false;
108 }
109
110 AttributeVector & protoDescList = *(protoDescAttr->getSequence());
111
112 for( unsigned int i = 0;
113 i < protoDescList.count();
114 i ++ ) {
115 AttributeVector & attrList = *(protoDescList[i]->getSequence());
116
117 //The List must have at least 2 Attributes
118 //Example:
119 // UUID16 : 0x0003 - RFCOMM
120 // Channel/Port (Integer) : 0x6
121 if(attrList.size() >= 2) {
122 // The first Attribute of the list must be an UUID
123 if( attrList[0]->getType() != OTSDPAttribute::UUID)
124 continue;
125 // The UUID must have the value of "0x0003" that's the RFCOMM UUID
126 OTUUID rfcommUUID( "0x0003" );
127 if( attrList[0]->getUUID() != rfcommUUID) //RFCOMM UUID
128 continue;
129 //If the UUID is ok we get the rfcomm channel number
130 if( attrList[1]->getType() != OTSDPAttribute::UINT)
131 continue;
132
133 n = attrList[1]->getUInt().lo;
134
135 return true;
136 }
137 }
138 // If we're here, we haven't found a correct Rfcomm channel, so we return false
139 return false;
140}
141
142bool OTSDPService::hasClassID(const OTUUID & uuid) {
143 OTSDPAttribute * ClassIDAttr;
144
145 // Get the the ClassID descriptor list attribute (0x01)
146 ClassIDAttr = attributeByID( 0x01);
147 if( ! ClassIDAttr ) {
148 return false;
149 }
150
151 AttributeVector & ClassIDList = *(ClassIDAttr->getSequence());
152 for( unsigned int i = 0 ;
153 i < ClassIDList.count() ;
154 i ++ ) {
155 if( ClassIDList[i]->getType() != OTSDPAttribute::UUID)
156 continue;
157 if( ClassIDList[i]->getUUID() == uuid)
158 return true;
159 }
160 return false;
161}
162
163/** Get a vector of UUID of the services class Id List */
164UUIDVector OTSDPService::classIDList( void ) {
165
166 UUIDVector uuidList;
167 OTSDPAttribute * ClassIDAttr;
168
169 // Get the the ClassID descriptor list attribute (0x01)
170 ClassIDAttr = attributeByID( 0x01);
171 if( ! ClassIDAttr ) {
172 return uuidList;
173 }
174
175 AttributeVector & ClassIDList = *(ClassIDAttr->getSequence());
176
177 for( unsigned int i = 0 ;
178 i < ClassIDList.count() ;
179 i ++ ) {
180 if( ClassIDList[i]->getType() != OTSDPAttribute::UUID)
181 continue;
182
183 uuidList.resize( uuidList.size() + 1 );
184 uuidList[ uuidList.size() - 1 ] = ClassIDList[i]->getUUID();
185 }
186
187 return uuidList;
188}
189
diff --git a/noncore/settings/networksettings2/opietooth2/OTSDPService.h b/noncore/settings/networksettings2/opietooth2/OTSDPService.h
new file mode 100644
index 0000000..4831df0
--- a/dev/null
+++ b/noncore/settings/networksettings2/opietooth2/OTSDPService.h
@@ -0,0 +1,75 @@
1//-*-c++-*-
2/***************************************************************************
3 * Copyright (C) 2003 by Fred Schaettgen *
4 * kdebluetooth@schaettgen.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 ***************************************************************************/
11
12#ifndef SDPSERVICE_H
13#define SDPSERVICE_H
14
15#include <qvector.h>
16#include <qarray.h>
17#include <OTSDPAttribute.h>
18
19namespace Opietooth2 {
20
21/**
22@author Fred Schaettgen
23*/
24class OTSDPService {
25
26public:
27
28 OTSDPService();
29 virtual ~OTSDPService();
30
31 void addAttribute(int id, OTSDPAttribute * attr);
32
33 const OTSDPAttribute & attribute( int index );
34 int attributeID( int index );
35
36 AttributeVector subAttributes( OTSDPAttribute * attr);
37 OTSDPAttribute * attributeByID( int id );
38
39 // See Bluetooth Core Spec Sec. 5.1
40 bool recordHandle(uint32_t *handle); // 0x00
41
42 //bool getServiceClassIDList(vector<uuid_t> *classIDList); // 0x01
43 //bool getServiceRecordState(uint32_t *state); // 0x02
44 //bool getServiceID(uuid_t *id); // 0x03;
45 //bool getProtocolDescriptorList(SDP::Attribute *attribute); // 0x04
46 //bool getBrowseGroupList(vector<uuid_t> *browseGroupList); // 0x05
47 QString name(void); // langBase + 0x00
48 QString description(void); // langBase + 0x01
49
50 UUIDVector allUUIDs();
51
52 // return list of classes this service belongs to
53 UUIDVector classIDList();
54
55 /** Retrieves the Rfcomm channel.
56 This function is provided just for conveniance.
57 @param n The Rfcomm channel.
58 @ret true if an rfcomm channel was found, false otherwise. */
59 bool rfcommChannel(unsigned int &n);
60
61 bool hasClassID(const OTUUID & uuid);
62
63private:
64
65 struct AttributeEntry {
66 int id;
67 OTSDPAttribute * attr;
68 };
69
70 QArray<AttributeEntry> attributeList;
71};
72
73}
74
75#endif
diff --git a/noncore/settings/networksettings2/opietooth2/OTScanGUI.ui b/noncore/settings/networksettings2/opietooth2/OTScanGUI.ui
new file mode 100644
index 0000000..66c19e6
--- a/dev/null
+++ b/noncore/settings/networksettings2/opietooth2/OTScanGUI.ui
@@ -0,0 +1,387 @@
1<!DOCTYPE UI><UI>
2<class>OTScanGUI</class>
3<widget>
4 <class>QWidget</class>
5 <property stdset="1">
6 <name>name</name>
7 <cstring>Form3</cstring>
8 </property>
9 <property stdset="1">
10 <name>geometry</name>
11 <rect>
12 <x>0</x>
13 <y>0</y>
14 <width>333</width>
15 <height>580</height>
16 </rect>
17 </property>
18 <property stdset="1">
19 <name>caption</name>
20 <string>Scanning</string>
21 </property>
22 <property>
23 <name>layoutMargin</name>
24 </property>
25 <property>
26 <name>layoutSpacing</name>
27 </property>
28 <vbox>
29 <property stdset="1">
30 <name>margin</name>
31 <number>0</number>
32 </property>
33 <property stdset="1">
34 <name>spacing</name>
35 <number>3</number>
36 </property>
37 <widget>
38 <class>QListView</class>
39 <column>
40 <property>
41 <name>text</name>
42 <string>Attribute</string>
43 </property>
44 <property>
45 <name>clickable</name>
46 <bool>true</bool>
47 </property>
48 <property>
49 <name>resizeable</name>
50 <bool>true</bool>
51 </property>
52 </column>
53 <column>
54 <property>
55 <name>text</name>
56 <string>Value</string>
57 </property>
58 <property>
59 <name>clickable</name>
60 <bool>true</bool>
61 </property>
62 <property>
63 <name>resizeable</name>
64 <bool>true</bool>
65 </property>
66 </column>
67 <property stdset="1">
68 <name>name</name>
69 <cstring>DetectedPeers_LV</cstring>
70 </property>
71 <property stdset="1">
72 <name>sizePolicy</name>
73 <sizepolicy>
74 <hsizetype>7</hsizetype>
75 <vsizetype>7</vsizetype>
76 </sizepolicy>
77 </property>
78 <property stdset="1">
79 <name>allColumnsShowFocus</name>
80 <bool>true</bool>
81 </property>
82 <property stdset="1">
83 <name>rootIsDecorated</name>
84 <bool>true</bool>
85 </property>
86 </widget>
87 <widget>
88 <class>QLayoutWidget</class>
89 <property stdset="1">
90 <name>name</name>
91 <cstring>Layout16</cstring>
92 </property>
93 <property>
94 <name>layoutSpacing</name>
95 </property>
96 <hbox>
97 <property stdset="1">
98 <name>margin</name>
99 <number>0</number>
100 </property>
101 <property stdset="1">
102 <name>spacing</name>
103 <number>3</number>
104 </property>
105 <widget>
106 <class>QPushButton</class>
107 <property stdset="1">
108 <name>name</name>
109 <cstring>Cleanup_But</cstring>
110 </property>
111 <property stdset="1">
112 <name>text</name>
113 <string>Cleanup</string>
114 </property>
115 </widget>
116 <spacer>
117 <property>
118 <name>name</name>
119 <cstring>Spacer1</cstring>
120 </property>
121 <property stdset="1">
122 <name>orientation</name>
123 <enum>Horizontal</enum>
124 </property>
125 <property stdset="1">
126 <name>sizeType</name>
127 <enum>Expanding</enum>
128 </property>
129 <property>
130 <name>sizeHint</name>
131 <size>
132 <width>20</width>
133 <height>20</height>
134 </size>
135 </property>
136 </spacer>
137 <widget>
138 <class>QPushButton</class>
139 <property stdset="1">
140 <name>name</name>
141 <cstring>Detect_But</cstring>
142 </property>
143 <property stdset="1">
144 <name>sizePolicy</name>
145 <sizepolicy>
146 <hsizetype>1</hsizetype>
147 <vsizetype>0</vsizetype>
148 </sizepolicy>
149 </property>
150 <property stdset="1">
151 <name>text</name>
152 <string>Scan</string>
153 </property>
154 <property stdset="1">
155 <name>toggleButton</name>
156 <bool>true</bool>
157 </property>
158 <property stdset="1">
159 <name>autoResize</name>
160 <bool>true</bool>
161 </property>
162 <property stdset="1">
163 <name>toggleButton</name>
164 <bool>true</bool>
165 </property>
166 </widget>
167 </hbox>
168 </widget>
169 <widget>
170 <class>QGroupBox</class>
171 <property stdset="1">
172 <name>name</name>
173 <cstring>Peer_GB</cstring>
174 </property>
175 <property stdset="1">
176 <name>title</name>
177 <string>GroupBox1</string>
178 </property>
179 <property>
180 <name>layoutMargin</name>
181 </property>
182 <property>
183 <name>layoutSpacing</name>
184 </property>
185 <grid>
186 <property stdset="1">
187 <name>margin</name>
188 <number>3</number>
189 </property>
190 <property stdset="1">
191 <name>spacing</name>
192 <number>3</number>
193 </property>
194 <widget row="2" column="0" rowspan="1" colspan="2" >
195 <class>QLayoutWidget</class>
196 <property stdset="1">
197 <name>name</name>
198 <cstring>Layout4</cstring>
199 </property>
200 <hbox>
201 <property stdset="1">
202 <name>margin</name>
203 <number>0</number>
204 </property>
205 <property stdset="1">
206 <name>spacing</name>
207 <number>6</number>
208 </property>
209 <widget>
210 <class>QFrame</class>
211 <property stdset="1">
212 <name>name</name>
213 <cstring>State_Frm</cstring>
214 </property>
215 <property stdset="1">
216 <name>sizePolicy</name>
217 <sizepolicy>
218 <hsizetype>7</hsizetype>
219 <vsizetype>5</vsizetype>
220 </sizepolicy>
221 </property>
222 <property stdset="1">
223 <name>frameShape</name>
224 <enum>NoFrame</enum>
225 </property>
226 <property stdset="1">
227 <name>frameShadow</name>
228 <enum>Raised</enum>
229 </property>
230 </widget>
231 <widget>
232 <class>QPushButton</class>
233 <property stdset="1">
234 <name>name</name>
235 <cstring>RefreshServices_But</cstring>
236 </property>
237 <property stdset="1">
238 <name>text</name>
239 <string>Services</string>
240 </property>
241 </widget>
242 <widget>
243 <class>QPushButton</class>
244 <property stdset="1">
245 <name>name</name>
246 <cstring>RefreshState_But</cstring>
247 </property>
248 <property stdset="1">
249 <name>text</name>
250 <string>State</string>
251 </property>
252 </widget>
253 </hbox>
254 </widget>
255 <widget row="0" column="1" >
256 <class>QLabel</class>
257 <property stdset="1">
258 <name>name</name>
259 <cstring>Address_LBL</cstring>
260 </property>
261 <property stdset="1">
262 <name>sizePolicy</name>
263 <sizepolicy>
264 <hsizetype>7</hsizetype>
265 <vsizetype>0</vsizetype>
266 </sizepolicy>
267 </property>
268 <property stdset="1">
269 <name>frameShape</name>
270 <enum>Panel</enum>
271 </property>
272 <property stdset="1">
273 <name>frameShadow</name>
274 <enum>Plain</enum>
275 </property>
276 <property stdset="1">
277 <name>lineWidth</name>
278 <number>1</number>
279 </property>
280 <property stdset="1">
281 <name>text</name>
282 <string></string>
283 </property>
284 <property stdset="1">
285 <name>indent</name>
286 <number>1</number>
287 </property>
288 </widget>
289 <widget row="0" column="0" >
290 <class>QLabel</class>
291 <property stdset="1">
292 <name>name</name>
293 <cstring>TextLabel1</cstring>
294 </property>
295 <property stdset="1">
296 <name>sizePolicy</name>
297 <sizepolicy>
298 <hsizetype>1</hsizetype>
299 <vsizetype>1</vsizetype>
300 </sizepolicy>
301 </property>
302 <property stdset="1">
303 <name>text</name>
304 <string>Address</string>
305 </property>
306 </widget>
307 <widget row="1" column="0" >
308 <class>QLabel</class>
309 <property stdset="1">
310 <name>name</name>
311 <cstring>TextLabel2</cstring>
312 </property>
313 <property stdset="1">
314 <name>text</name>
315 <string>Signal strength</string>
316 </property>
317 </widget>
318 <widget row="1" column="1" >
319 <class>QProgressBar</class>
320 <property stdset="1">
321 <name>name</name>
322 <cstring>Strength_PB</cstring>
323 </property>
324 <property stdset="1">
325 <name>centerIndicator</name>
326 <bool>true</bool>
327 </property>
328 <property stdset="1">
329 <name>indicatorFollowsStyle</name>
330 <bool>false</bool>
331 </property>
332 </widget>
333 </grid>
334 </widget>
335 </vbox>
336</widget>
337<connections>
338 <connection>
339 <sender>RefreshServices_But</sender>
340 <signal>clicked()</signal>
341 <receiver>Form3</receiver>
342 <slot>SLOT_RefreshServices()</slot>
343 </connection>
344 <connection>
345 <sender>Detect_But</sender>
346 <signal>toggled(bool)</signal>
347 <receiver>Form3</receiver>
348 <slot>SLOT_DoScan( bool )</slot>
349 </connection>
350 <connection>
351 <sender>Cleanup_But</sender>
352 <signal>clicked()</signal>
353 <receiver>Form3</receiver>
354 <slot>SLOT_CleanupOld()</slot>
355 </connection>
356 <connection>
357 <sender>RefreshState_But</sender>
358 <signal>clicked()</signal>
359 <receiver>Form3</receiver>
360 <slot>SLOT_RefreshState()</slot>
361 </connection>
362 <connection>
363 <sender>DetectedPeers_LV</sender>
364 <signal>clicked(QListViewItem*)</signal>
365 <receiver>Form3</receiver>
366 <slot>SLOT_Show(QListViewItem *)</slot>
367 </connection>
368 <connection>
369 <sender>DetectedPeers_LV</sender>
370 <signal>currentChanged(QListViewItem*)</signal>
371 <receiver>Form3</receiver>
372 <slot>SLOT_Show(QListViewItem *)</slot>
373 </connection>
374 <connection>
375 <sender>DetectedPeers_LV</sender>
376 <signal>doubleClicked(QListViewItem*)</signal>
377 <receiver>Form3</receiver>
378 <slot>SLOT_Selected(QListViewItem*)</slot>
379 </connection>
380 <slot access="public">SLOT_CleanupOld()</slot>
381 <slot access="public">SLOT_DoScan( bool )</slot>
382 <slot access="public">SLOT_RefreshServices()</slot>
383 <slot access="public">SLOT_RefreshState()</slot>
384 <slot access="public">SLOT_Selected(QListViewItem*)</slot>
385 <slot access="public">SLOT_Show(QListViewItem *)</slot>
386</connections>
387</UI>
diff --git a/noncore/settings/networksettings2/opietooth2/OTUUID.cpp b/noncore/settings/networksettings2/opietooth2/OTUUID.cpp
new file mode 100644
index 0000000..4b05a7a
--- a/dev/null
+++ b/noncore/settings/networksettings2/opietooth2/OTUUID.cpp
@@ -0,0 +1,162 @@
1//-*-c++-*-
2/***************************************************************************
3 * Copyright (C) 2003 by Fred Schaettgen *
4 * kdebluetooth@schaettgen.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 ***************************************************************************/
11
12#include <assert.h>
13#include <qregexp.h>
14#include <opie2/odebug.h>
15
16#include <OTUUID.h>
17
18using namespace Opietooth2;
19
20OTUUID::OTUUID(QString s) {
21 fromString(s);
22}
23
24OTUUID::OTUUID(uint64_t l, uint64_t h) {
25 this->hi = h;
26 this->lo = l;
27}
28
29OTUUID::OTUUID( const OTUUID & O ) {
30 this->hi = O.hi;
31 this->lo = O.lo;
32}
33
34OTUUID & OTUUID::operator =( const OTUUID & O ) {
35 hi = O.hi;
36 lo = O.lo;
37 return *this;
38}
39
40bool OTUUID::fromString(QString s) {
41
42 // Strip leading "0x"
43 if (s.startsWith("0x"))
44 {
45 s = s.right(s.length()-2);
46 }
47 // Remove separators
48 s.replace( QRegExp(":"), "" );
49
50 bool bOk = false;
51 if( s.length() == 4 || s.length() == 8) {
52
53 uint32_t u32 = s.toUInt(&bOk, 16);
54 setUUID32(u32);
55 return bOk;
56
57 } else if (s.length() == 32) {
58
59#if (QT_VERSION >= 0x030200)
60 uint64_t u64hi = s.left(16).toULongLong(&bOk, 16);
61#else
62 uint64_t u64hi = s.left(16).toULong(&bOk, 16);
63#endif
64 if (!bOk)
65 return false;
66
67#if (QT_VERSION >= 0x030200)
68 uint64_t u64lo = s.right(16).toULongLong(&bOk, 16);
69#else
70 uint64_t u64lo = s.right(16).toULong(&bOk, 16);
71#endif
72 if (!bOk)
73 return false;
74 hi = u64hi;
75 lo = u64lo;
76 return true;
77
78 } else {
79 hi = 0;
80 lo = 0;
81 return true;
82 }
83}
84
85void OTUUID::setUUID32(uint32_t v) {
86
87 hi = uint64_t(0x1000) | (uint64_t(v) << 32);
88 // see BT 1.1 Core spec p2.7.1
89 lo = (uint64_t(0x80000080) << 32) | uint64_t(0x5F9B34FB);
90
91}
92
93void OTUUID::setUUID128(uint64_t _hi, uint64_t _lo) {
94 hi = _hi;
95 lo = _lo;
96}
97
98QString OTUUID::toString() const {
99 QString ret;
100 uint32_t v1 = uint32_t(hi >> 32);
101 uint32_t v2 = uint32_t(hi & 0xFFFFFFFF);
102 uint32_t v3 = uint32_t(lo >> 32);
103 uint32_t v4 = uint32_t(lo & 0xFFFFFFFF);
104 ret.sprintf("0x%08lx:%08lx:%08lx:%08lx",
105 (unsigned long)v1, (unsigned long)v2,
106 (unsigned long)v3, (unsigned long)v4);
107
108 return ret;
109}
110
111OTUUID::operator QString() const {
112 return toString();
113}
114
115OTUUID::operator ::uuid_t() const {
116
117 //kdDebug() << "uuid_t() -> " << QString(*this) << endl;
118 ::uuid_t ret;
119 if ((lo == (uint64_t(0x80000080) << 32) | uint64_t(0x5F9B34FB)) &&
120 ((hi&0xFFFFFFFF) == 0x1000)) {
121 uint32_t uuid32val = uint32_t(hi >> 32);
122 if (uuid32val > 0xFFFF) {
123 ret.type = SDP_UUID16;
124 ret.value.uuid16 = uint16_t(uuid32val);
125 } else {
126 ret.type = SDP_UUID32;
127 ret.value.uuid32 = uuid32val;
128 }
129 } else {
130 ret.value.uuid128.data[0] = (lo >> 0) && 0xFF;
131 ret.value.uuid128.data[1] = (lo >> 8) && 0xFF;
132 ret.value.uuid128.data[2] = (lo >> 16) && 0xFF;
133 ret.value.uuid128.data[3] = (lo >> 24) && 0xFF;
134 ret.value.uuid128.data[4] = (lo >> 32) && 0xFF;
135 ret.value.uuid128.data[5] = (lo >> 40) && 0xFF;
136 ret.value.uuid128.data[6] = (lo >> 48) && 0xFF;
137 ret.value.uuid128.data[7] = (lo >> 56) && 0xFF;
138
139 ret.value.uuid128.data[8] = (hi >> 0) && 0xFF;
140 ret.value.uuid128.data[9] = (hi >> 8) && 0xFF;
141 ret.value.uuid128.data[10] = (hi >> 16) && 0xFF;
142 ret.value.uuid128.data[11] = (hi >> 24) && 0xFF;
143 ret.value.uuid128.data[12] = (hi >> 32) && 0xFF;
144 ret.value.uuid128.data[13] = (hi >> 40) && 0xFF;
145 ret.value.uuid128.data[14] = (hi >> 48) && 0xFF;
146 ret.value.uuid128.data[15] = (hi >> 56) && 0xFF;
147
148 ret.type = SDP_UUID128;
149 }
150 return ret;
151}
152
153bool OTUUID::operator<(const OTUUID & other) const {
154 if (hi != other.hi)
155 return hi < other.hi;
156
157 return lo<other.lo;
158}
159
160bool OTUUID::operator ==(const OTUUID& u) const {
161 return (u.hi == hi) && (u.lo == lo);
162}
diff --git a/noncore/settings/networksettings2/opietooth2/OTUUID.h b/noncore/settings/networksettings2/opietooth2/OTUUID.h
new file mode 100644
index 0000000..aebd9b9
--- a/dev/null
+++ b/noncore/settings/networksettings2/opietooth2/OTUUID.h
@@ -0,0 +1,58 @@
1//-*-c++-*-
2/***************************************************************************
3 * Copyright (C) 2003 by Fred Schaettgen *
4 * kdebluetooth@schaettgen.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 ***************************************************************************/
11
12#ifndef OTUUID_H
13#define OTUUID_H
14
15#include <qstring.h>
16#include <qarray.h>
17#include <bluezlib.h>
18
19namespace Opietooth2 {
20
21class OTUUID;
22
23typedef QArray<OTUUID> UUIDVector;
24
25class OTUUID {
26
27public :
28
29 OTUUID( QString s );
30 OTUUID( uint64_t l=0, uint64_t h=0);
31 OTUUID( const OTUUID & O );
32
33 bool fromString(QString s);
34
35 void setUUID128(uint64_t hi, uint64_t lo);
36
37 void setUUID32(uint32_t v);
38
39 uint16_t toShort()
40 { return ((hi>>32) & 0xffff); }
41 uint32_t toLong()
42 { return ((hi>>32) & 0xffffffff); }
43 uint64_t toLongLong()
44 { return hi; }
45
46 QString toString() const ;
47 operator QString() const;
48 operator ::uuid_t() const;
49
50 OTUUID & operator=( const OTUUID & other ) ;
51 bool operator<( const OTUUID & other ) const;
52 bool operator==(const OTUUID & uuid) const;
53
54 uint64_t hi;
55 uint64_t lo;
56};
57}
58#endif
diff --git a/noncore/settings/networksettings2/opietooth2/Opietooth.cpp b/noncore/settings/networksettings2/opietooth2/Opietooth.cpp
new file mode 100644
index 0000000..8d71f32
--- a/dev/null
+++ b/noncore/settings/networksettings2/opietooth2/Opietooth.cpp
@@ -0,0 +1,1003 @@
1#include <opie2/odebug.h>
2#include <opie2/oledbox.h>
3
4#include <qpe/resource.h>
5#include <qcheckbox.h>
6#include <qgroupbox.h>
7#include <qlabel.h>
8#include <qprogressbar.h>
9#include <qheader.h>
10#include <qmessagebox.h>
11#include <qapplication.h>
12#include <qlistbox.h>
13#include <qdialog.h>
14#include <qlayout.h>
15#include <qcombobox.h>
16#include <qlabel.h>
17#include <qlistview.h>
18#include <qpushbutton.h>
19
20#include <Opietooth.h>
21#include <OTDriver.h>
22#include <OTPeer.h>
23#include <OTGateway.h>
24#include <OTSDPAttribute.h>
25#include <OTSDPService.h>
26#include <OTInquiry.h>
27
28using namespace Opietooth2;
29
30namespace Opietooth2 {
31
32class PeerLVI : public QListViewItem {
33
34public :
35
36 PeerLVI( OTPeer * P, QListView * it ) : QListViewItem (it) {
37 Peer = P;
38 }
39 ~PeerLVI( void ) {
40 }
41
42 inline OTPeer * peer( void )
43 { return Peer; }
44
45private :
46
47 OTPeer * Peer;
48};
49
50class ChannelLVI : public QListViewItem {
51
52public :
53
54 ChannelLVI( int Ch, QListViewItem * it ) : QListViewItem (it) {
55 Channel = Ch;
56 }
57 ~ChannelLVI( void ) {
58 }
59
60 inline int channel( void )
61 { return Channel; }
62
63private :
64
65 int Channel;
66};
67
68class DriverLVI : public QListViewItem {
69
70public :
71
72 DriverLVI( OTDriver * P, QListView * it ) : QListViewItem (it) {
73 Driver = P;
74 }
75 ~DriverLVI( void ) {
76 }
77
78 inline OTDriver * driver( void )
79 { return Driver; }
80
81private :
82
83 OTDriver * Driver;
84};
85
86class LinkKeyLVI : public QListViewItem {
87
88public :
89
90 LinkKeyLVI( int Ch, QListView * it ) : QListViewItem (it) {
91 LinkKey = Ch;
92 }
93 ~LinkKeyLVI( void ) {
94 }
95
96 inline int index( void )
97 { return LinkKey; }
98
99private :
100
101 int LinkKey;
102};
103};
104
105//
106//
107//
108//
109//
110
111OTPairing::OTPairing( QWidget * parent, OTIcons * _IC ) :
112 OTPairingGUI( parent ) {
113
114 OT = OTGateway::getOTGateway();
115 Icons = (_IC ) ? _IC : new OTIcons();
116 MyIcons = (_IC == 0 );
117
118 // unpairing can only be done if bluetooth is disabled
119 Unpair_But->setEnabled( ! OT->isEnabled() );
120 if( ! OT->isEnabled() ) {
121 Unpair_LBL->hide();
122 } else {
123 Unpair_LBL->show();
124 }
125
126 // open linkkey file and load pairs
127 LinkKeyArray Keys = OT->getLinkKeys();
128 LinkKeyLVI * it;
129 OTPeer * P;
130 OTDriver * D;
131
132 for( unsigned int i = 0 ;
133 i < Keys.count();
134 i ++ ) {
135
136 it = new LinkKeyLVI( i, Pairs_LV );
137
138 P = 0;
139 D = OT->findDriver( Keys[i].from() );
140
141 if( D ) {
142 it->setText( 0, D->devname() );
143
144 // we are source
145 P = OT->findPeer( Keys[i].to() );
146
147 if( P ) {
148 // put name
149 it->setText( 1, P->name() );
150 } else {
151 // unknown
152 it->setText( 1, Keys[i].to().toString() );
153 }
154
155 // and put address as sub
156 QListViewItem * Sub = new QListViewItem( it );
157 Sub->setText( 0, D->address().toString() );
158 Sub->setText( 1, Keys[i].to().toString() );
159 } else {
160 // perhaps we are destination
161 D = OT->findDriver( Keys[i].to() );
162
163 if( D ) {
164 it->setText( 1, D->devname() );
165
166 // we are source
167 P = OT->findPeer( Keys[i].from() );
168
169 if( P ) {
170 // put name
171 it->setText( 0, P->name() );
172 } else {
173 // unknown
174 it->setText( 0, Keys[i].from().toString() );
175 }
176
177 // and put address as sub
178 QListViewItem * Sub = new QListViewItem( it );
179 Sub->setText( 0, Keys[i].from().toString() );
180 Sub->setText( 1, D->address().toString() );
181 } else {
182 // nor source nor destination -> unknown
183 it->setText( 0, Keys[i].from().toString() );
184 it->setText( 1, Keys[i].to().toString() );
185 }
186 }
187 }
188}
189
190
191OTPairing::~OTPairing() {
192 if( MyIcons )
193 delete Icons;
194 OTGateway::releaseOTGateway();
195}
196
197void OTPairing::SLOT_Unpair( ) {
198 // find selected pair
199
200 QListViewItem * it = Pairs_LV->firstChild();
201 while( it ) {
202 if( it->isSelected() ) {
203 // confirm ?
204 if( QMessageBox::warning(0,
205 tr("Break pairing"),
206 tr("Sure ?"),
207 tr("Yes, break"),
208 tr("No, don't break") ) == 0 ) {
209 LinkKeyLVI * KPIt = (LinkKeyLVI *)it;
210 // break
211 OT->removeLinkKey( KPIt->index() );
212 delete KPIt;
213 }
214 return;
215 }
216 it= it->nextSibling();
217 }
218}
219
220//
221//
222//
223//
224//
225
226OTScan::OTScan( QWidget * parent, OTIcons * _IC ) :
227 OTScanGUI( parent ), Filter() {
228
229 OT = OTGateway::getOTGateway();
230 Icons = (_IC ) ? _IC : new OTIcons();
231 MyIcons = (_IC == 0 );
232 DetectedPeers_LV->header()->hide();
233 Current = 0;
234 SelectedPeer = 0;
235 SelectedChannel = 0;
236
237 StrengthTimer = new QTimer( this );
238 connect( StrengthTimer,
239 SIGNAL( timeout()),
240 this,
241 SLOT( SLOT_UpdateStrength())
242 );
243
244 connect( OT,
245 SIGNAL( detectedPeer( OTPeer *, bool )),
246 this,
247 SLOT( SLOT_NewPeer( OTPeer *, bool ))
248 );
249 connect( OT,
250 SIGNAL( finishedDetecting()),
251 this,
252 SLOT( SLOT_FinishedDetecting())
253 );
254
255 // populate with peers we already know about
256 const PeerVector & P = OT->peers();
257 for( unsigned int i = 0;
258 i < P.count();
259 i ++ ) {
260 SLOT_NewPeer( P[i], TRUE );
261 }
262
263 // populate State fram
264 { QHBoxLayout * H =new QHBoxLayout( State_Frm );
265
266 Paired_Led = new OLedBox( green, State_Frm );
267 QLabel * L1 = new QLabel( tr( "Paired" ), State_Frm );
268
269 H->addWidget( Paired_Led );
270 H->addWidget( L1 );
271 H->addStretch( 1 );
272 }
273}
274
275OTScan::~OTScan() {
276 if( MyIcons )
277 delete Icons;
278 OTGateway::releaseOTGateway();
279
280 // send all peers that we do not care about states
281 QListViewItem * Lit = DetectedPeers_LV->firstChild();
282 while( Lit ) {
283 ((PeerLVI *)Lit)->peer()->stopFindingOutState( );
284 Lit = Lit->nextSibling();
285 }
286}
287
288// static scan dialog function
289int OTScan::getDevice( OTPeer *& Peer,
290 int & Channel,
291 OTGateway * OT,
292 const UUIDVector & Filter,
293 QWidget* Parent ) {
294 bool IsUp = 0;
295 unsigned int i;
296
297 // check if bluetooth is up
298 OTDriverList & DL = OT->getDriverList();
299 for( i = 0;
300 i < DL.count();
301 i ++ ) {
302 if( DL[i]->isUp() ) {
303 // one device that is up found
304 IsUp = 1;
305 break;
306 }
307 }
308
309 // use this driver
310 OT->setScanWith( OT->driver(i) );
311
312 // create dialog
313 QDialog * Dlg = new QDialog( Parent, 0, TRUE );
314 QVBoxLayout * V = new QVBoxLayout( Dlg );
315 OTScan * Scn = new OTScan( Dlg );
316
317 connect( Scn,
318 SIGNAL( selected() ),
319 Dlg,
320 SLOT( accept() )
321 );
322
323 if( Filter ) {
324 Scn->setScanFilter( Filter );
325 }
326
327 V->addWidget( Scn );
328 Dlg->setCaption( tr("Scan Neighbourhood" ) );
329 Dlg->showMaximized();
330 int rv = Dlg->exec();
331
332 if( rv == QDialog::Accepted ) {
333 // get peer
334 Peer = Scn->selectedPeer();
335 if( Peer == 0 ) {
336 // no peer selected
337 rv = QDialog::Rejected;
338 } else {
339 Channel = Scn->selectedChannel();
340 }
341 }
342
343 delete Dlg;
344
345 return rv;
346}
347
348void OTScan::setScanFilter( const UUIDVector & V ) {
349 Filter = V;
350}
351
352void OTScan::resetScanFilter( void ) {
353 Filter.truncate(0);
354}
355
356void OTScan::SLOT_DoScan( bool DoIt ) {
357 if( DoIt ) {
358 OT->scanNeighbourhood();
359 } else {
360 OT->stopScanOfNeighbourhood();
361 }
362
363 scanMode( DoIt );
364}
365
366// double clicked on a device
367void OTScan::SLOT_Selected( QListViewItem * it ) {
368 if( ! it )
369 return;
370
371 if( Filter.count() > 0 ) {
372 // filter on service
373 if( it->depth() == 0 ) {
374 // select a service and not a device
375 return;
376 }
377
378 // store result
379 SelectedPeer = ((PeerLVI *)it->parent())->peer();
380 SelectedChannel = ((ChannelLVI *)it)->channel();
381 } else {
382 // click on device
383 if( it->depth() != 0 ) {
384 return;
385 }
386
387 SelectedPeer = ((PeerLVI *)it)->peer();
388 SelectedChannel = 0;
389 }
390 owarn << "Selected " << SelectedPeer->address().toString() <<
391 " Channel " << SelectedChannel << oendl;
392 emit selected();
393}
394
395void OTScan::SLOT_FinishedDetecting( ) {
396 scanMode( false );
397}
398
399void OTScan::SLOT_CleanupOld( ) {
400
401 // iterate over all peers and find those that
402 // are down and have no pairing info
403 OTPeer * TheP;
404 const LinkKeyArray & Keys = OT->getLinkKeys();
405
406 QListViewItem * Lit = DetectedPeers_LV->firstChild();
407 while( Lit ) {
408 TheP = ((PeerLVI *)Lit)->peer();
409 if( TheP->state() == OTPeer::Peer_Down ) {
410 unsigned int k;
411
412 // what about linkkeys ?
413 for( k = 0; k < Keys.count(); k ++ ) {
414 if( TheP->address() == Keys[k].to() ||
415 TheP->address() == Keys[k].from()
416 ) {
417 // part of linkkey
418 owarn << "LINKKEY " << TheP->address().toString() << oendl;
419 break;
420 }
421 }
422
423 if( k == Keys.count() ) {
424 owarn << "RM LINKKEY " << TheP->address().toString() << oendl;
425 // not found -> remember to remove this peer
426 QListViewItem * Nit;
427 OT->removePeer( TheP );
428 Nit = Lit->nextSibling();
429 delete Lit;
430 Lit = Nit;
431 continue;
432 }
433 } else {
434 owarn << "NODOWN " << TheP->address().toString() << oendl;
435 }
436
437 Lit = Lit->nextSibling();
438 }
439}
440
441void OTScan::SLOT_NewPeer( OTPeer * P, bool IsNew ){
442 PeerLVI * it = 0;
443
444 if( IsNew ) {
445 it = new PeerLVI( P, DetectedPeers_LV );
446 } else {
447 // find peer in table
448 QListViewItem * Lit = DetectedPeers_LV->firstChild();
449 while( Lit ) {
450 if( ((PeerLVI *)Lit)->peer() == P ) {
451 // this item
452 it = (PeerLVI *)Lit;
453 break;
454 }
455 Lit = Lit->nextSibling();
456 }
457
458 if( ! it ) {
459 owarn << "Should not occur" << oendl;
460 return;
461 }
462 }
463
464 // update/show info
465 it->setText( 0, P->name() );
466 it->setPixmap(0, Icons->deviceIcon(
467 OT->deviceTypeToName( P->deviceClass() ) ) );
468
469 // tell peer to report its state async
470 connect( P,
471 SIGNAL( peerStateReport( OTPeer *)),
472 this,
473 SLOT( SLOT_PeerState( OTPeer *))
474 );
475
476 if( IsNew ) {
477 // find state
478 refreshState( (PeerLVI *)it, 1 );
479 } else {
480 // update staet
481 SLOT_PeerState( P );
482 }
483}
484
485void OTScan::SLOT_PeerState( OTPeer * P ) {
486 PeerLVI * it = (PeerLVI *)DetectedPeers_LV->firstChild();
487 while( it ) {
488 if( it->peer() == P ) {
489 break;
490 }
491 it = (PeerLVI * )it->nextSibling();
492 }
493
494 if( ! it )
495 return;
496
497 switch( P->state() ) {
498 case OTPeer::Peer_Unknown :
499 case OTPeer::Peer_Down :
500 it->setPixmap( 1, 0 );
501 break;
502 case OTPeer::Peer_Up :
503 it->setPixmap( 1, Icons->loadPixmap(
504 ( P->connectedTo() ) ? "connected" : "notconnected" ) );
505 if( it == Current && ! StrengthTimer->isActive() ) {
506 // start showing strength
507 StrengthTimer->start( 1000, FALSE );
508 SLOT_UpdateStrength();
509 }
510 break;
511 }
512}
513
514void OTScan::SLOT_RefreshState( void ) {
515
516 QListViewItem * it = DetectedPeers_LV->firstChild();
517 while( it ) {
518 if( it->isSelected() ) {
519 break;
520 }
521 it = it->nextSibling();
522 }
523
524 if( ! it )
525 return;
526
527 refreshState( (PeerLVI *)it, 1 );
528}
529
530void OTScan::refreshState( PeerLVI * it, bool Force ) {
531 it->setPixmap( 1, Icons->loadPixmap( "find" ) );
532 it->peer()->findOutState( 30, Force );
533}
534
535void OTScan::SLOT_Show( QListViewItem * it ) {
536
537 if( ! it || it->depth() > 0 )
538 return;
539
540 QString S;
541
542 Current = (PeerLVI *)it;
543
544 Strength_PB->setProgress( 0 ); // reset
545 Address_LBL->setText( Current->peer()->address().toString() );
546 Peer_GB->setTitle( Current->peer()->name() );
547
548 const LinkKeyArray & Keys = OT->getLinkKeys();
549
550 Paired_Led->setOn( FALSE );
551 for( unsigned int i = 0;
552 i < Keys.count();
553 i ++ ) {
554 if( Current->peer()->address() == Keys[i].to() ) {
555 Paired_Led->setOn( TRUE );
556 break;
557 }
558 }
559
560 if( Current->peer()->state() == OTPeer::Peer_Up ) {
561 RefreshServices_But->setEnabled( TRUE );
562 StrengthTimer->start( 1000, FALSE );
563 SLOT_UpdateStrength();
564 } else {
565 RefreshServices_But->setEnabled( FALSE );
566 }
567
568}
569
570void OTScan::SLOT_UpdateStrength( void ) {
571 OTDriver * D = Current->peer()->connectedTo();
572
573 if( D ) {
574 long Q = D->getLinkQuality( Current->peer()->address() );
575 Strength_PB->setProgress( Q );
576 if( ! Q ) {
577 // no quality
578 Strength_PB->setEnabled( TRUE );
579 StrengthTimer->stop();
580 }
581 } else {
582 Strength_PB->setEnabled( FALSE );
583 Strength_PB->setProgress( 0 );
584 // no point in continuing
585 StrengthTimer->stop();
586 }
587}
588
589void OTScan::SLOT_RefreshServices( void ) {
590
591 QListViewItem * it = DetectedPeers_LV->firstChild();
592 while( it ) {
593 if( it->isSelected() ) {
594 break;
595 }
596 it = it->nextSibling();
597 }
598
599 if( ! it )
600 return;
601
602 QString S;
603 PeerLVI * PI = (PeerLVI *)it;
604
605 scanMode( true );
606 qApp->processEvents(0);
607
608 ServiceVector & V = PI->peer()->services();
609
610 while( PI->firstChild() ) {
611 // remove children
612 delete PI->firstChild();
613 }
614
615 for( unsigned int i = 0 ;
616 i < V.count();
617 i ++ ) {
618 QString S;
619 S = V[i]->name();
620
621 if( S.isEmpty() ) {
622 continue;
623 }
624
625 { QListViewItem * SIt;
626 UUIDVector UIDV;
627 QPixmap Pm;
628 bool Done = 0;
629 bool R;
630 short ID;
631
632 SIt = 0;
633
634 UIDV = V[i]->classIDList();
635 // first all UUID ! 1200 12ff (Genericprofiles)
636 for( unsigned int j = 0;
637 j < UIDV.count();
638 j ++ ) {
639
640 if( Filter.count() ) {
641 bool FilterOut = 1;
642 // filter out if not in list
643 for( unsigned int ff = 0;
644 ff < Filter.count();
645 ff ++ ) {
646 if( UIDV[j] == Filter[ff] ) {
647 FilterOut = 0;
648 break;
649 }
650 }
651
652 if( FilterOut ) {
653 // not in filter list
654 continue;
655 }
656 } // else show
657
658 ID = UIDV[j].toShort();
659 if( ID < 0x1200 || ID > 0x12ff ) {
660 // use this profile
661 if( R ) {
662 unsigned int ch;
663 bool has;
664 has = V[i]->rfcommChannel( ch );
665 SIt = new ChannelLVI( (has) ? (int)ch : -1 , PI );
666 SIt->setText(0, V[i]->name() );
667
668 Pm = Icons->serviceIcon( ID, R );
669 SIt->setPixmap(0, Pm );
670 Done = 1;
671 break;
672 }
673 }
674 }
675
676 if( ! Done ) {
677 // check other range too
678 for( unsigned int j = 0;
679 j < UIDV.count();
680 j ++ ) {
681
682 if( Filter.count() ) {
683 bool FilterOut = 1;
684 // filter out if not in list
685 for( unsigned int ff = 0;
686 ff < Filter.count();
687 ff ++ ) {
688 if( UIDV[j] == Filter[ff] ) {
689 FilterOut = 0;
690 break;
691 }
692 }
693
694 if( FilterOut ) {
695 // not in filter list
696 continue;
697 }
698 } // else show
699
700 ID = UIDV[j].toShort();
701 if( ID >= 0x1200 && ID <= 0x12ff ) {
702 // use this profile
703 unsigned int ch;
704 bool has;
705 has = V[i]->rfcommChannel( ch );
706 SIt = new ChannelLVI( (has) ? (int)ch : -1 , PI );
707 SIt->setText(0, V[i]->name() );
708
709 Pm = Icons->serviceIcon( ID, R );
710 SIt->setPixmap(0, Pm );
711
712 break;
713 }
714 }
715 }
716
717 }
718 }
719
720 scanMode( false );
721}
722
723void OTScan::scanMode( bool M ) {
724 // avoid infinite loop because it triggers DoScan
725 Detect_But->blockSignals( TRUE );
726 Detect_But->setOn( M );
727 Detect_But->setText( (M) ? tr("Scanning") : tr("Scan") );
728 Detect_But->blockSignals( FALSE );
729}
730
731//
732//
733//
734//
735//
736
737OTManage::OTManage( QWidget * parent, OTIcons * _IC ) :
738 OTManageGUI( parent ) {
739
740 OT = OTGateway::getOTGateway();
741
742 Icons = (_IC ) ? _IC : new OTIcons();
743 MyIcons = (_IC == 0 );
744 AllDrivers_LV->setSorting(-1);
745
746 connect( OT,
747 SIGNAL( driverListChanged() ),
748 this,
749 SLOT( SLOT_DriverListChanged() )
750 );
751 connect( OT,
752 SIGNAL( stateChange( OTDriver *, bool ) ),
753 this,
754 SLOT( SLOT_StateChange( OTDriver *, bool ) )
755 );
756
757 SLOT_DriverListChanged();
758
759 AllDrivers_LV->header()->hide();
760}
761
762OTManage::~OTManage() {
763 if( MyIcons )
764 delete Icons;
765 OTGateway::releaseOTGateway();
766}
767
768void OTManage::SLOT_ShowDriver( QListViewItem * It ) {
769 if( It == 0 || It->depth() > 0 )
770 // not toplevel
771 return;
772
773 DriverLVI * it = (DriverLVI *) It;
774 DriverIsUp_CB->setChecked( it->driver()->isUp() );
775}
776
777void OTManage::SLOT_UpDriver( bool Up ) {
778 QListViewItem * it = AllDrivers_LV->firstChild();
779 while( it ) {
780 if( it->isSelected() ) {
781 OTDriver * D = ((DriverLVI *)it)->driver();
782 owarn << "UP driver " << D->devname() << oendl;
783 // this
784 D->setUp( Up );
785 return;
786 }
787 it = it->nextSibling();
788 }
789}
790
791void OTManage::SLOT_StateChange( OTDriver * D, bool Up ) {
792 QListViewItem * it = AllDrivers_LV->firstChild();
793 while( it ) {
794 if( ((DriverLVI *)it)->driver() == D ) {
795 it->setPixmap( 0,
796 Icons->loadPixmap( ( Up ) ? "bluezon" : "bluezoff" ) );
797 return;
798 }
799 it = it->nextSibling();
800 }
801}
802
803void OTManage::SLOT_DriverListChanged( ) {
804 DriverLVI * It;
805 QListViewItem * Sub;
806 QListViewItem * First = 0;
807 OTDriver* D;
808 OTDriverList & DL = OT->getDriverList();
809
810 AllDrivers_LV->clear();
811 for( unsigned int i = 0;
812 i < DL.count();
813 i ++ ) {
814 D = DL[i];
815 It = new DriverLVI( D, AllDrivers_LV );
816
817 if( ! First )
818 First = It;
819
820 It->setText( 0, D->devname() );
821 It->setPixmap( 0,
822 Icons->loadPixmap( (D->isUp()) ?
823 "bluezon" : "bluezoff" ) );
824
825 Sub = new QListViewItem( It );
826 Sub->setText( 0, tr( "Name" ) );
827 Sub->setText( 1, D->name() );
828
829 Sub = new QListViewItem( It );
830 Sub->setText( 0, tr( "Address" ) );
831 Sub->setText( 1, D->address().toString() );
832
833 Sub = new QListViewItem( It );
834 Sub->setText( 0, tr( "Revision" ) );
835 Sub->setText( 1, D->revision() );
836
837 Sub = new QListViewItem( It );
838 Sub->setText( 0, tr( "Manufacturer" ) );
839 Sub->setText( 1, D->manufacturer() );
840
841 QString Service, Device;
842 D->getClass( Service, Device );
843
844 Sub = new QListViewItem( It );
845 Sub->setText( 0, tr( "Service classes" ) );
846 Sub->setText( 1, Service );
847 Sub = new QListViewItem( It );
848 Sub->setText( 0, tr( "Device class" ) );
849 Sub->setText( 1, Device );
850 }
851
852 if( DL.count() ) {
853 AllDrivers_LV->setCurrentItem( First );
854 DriverIsUp_CB->setEnabled( TRUE );
855 } else {
856 DriverIsUp_CB->setChecked( FALSE );
857 DriverIsUp_CB->setEnabled( FALSE );
858 }
859}
860
861void OTManage::SLOT_SetRefreshTimer( int v ) {
862 OT->setRefreshTimer( v * 1000 );
863}
864
865//
866//
867//
868//
869//
870
871OTMain::OTMain( QWidget * parent ) : OTMainGUI( parent ) {
872
873 Icons = new OTIcons();
874 OT = OTGateway::getOTGateway();
875
876 connect( OT,
877 SIGNAL( deviceEnabled( bool ) ),
878 this,
879 SLOT( SLOT_DeviceIsEnabled( bool ) )
880 );
881 connect( OT,
882 SIGNAL( driverListChanged() ),
883 this,
884 SLOT( SLOT_DriverListChanged() )
885 );
886 connect( OT,
887 SIGNAL( stateChange( OTDriver *, bool ) ),
888 this,
889 SLOT( SLOT_StateChange( OTDriver *, bool ) )
890 );
891
892 if( ! OT->needsEnabling() ) {
893 MustBeEnabled_CB->hide();
894 } else {
895 // detect current state
896 MustBeEnabled_CB->setChecked(
897 OT->isEnabled() );
898 }
899
900 SLOT_DriverListChanged();
901}
902
903OTMain::~OTMain() {
904 OTGateway::releaseOTGateway();
905 delete Icons;
906}
907
908void OTMain::SLOT_DriverListChanged() {
909 OTDriver * D;
910 OTDriverList & DL = OT->getDriverList();
911
912 DeviceList_CB->clear();
913 for( unsigned int i = 0;
914 i < DL.count();
915 i ++ ) {
916 D = DL[i];
917 DeviceList_CB->insertItem(
918 Icons->loadPixmap( (D->isUp()) ?
919 "bluezon" : "bluezoff" ),
920 D->devname() );
921 if( D == OT->scanWith() ) {
922 DeviceList_CB->setCurrentItem( i );
923 }
924 }
925
926 Scan_But->setEnabled( OT->getDriverList().count() > 0 );
927 DeviceList_CB->setEnabled( OT->getDriverList().count() > 0 );
928}
929
930void OTMain::SLOT_EnableBluetooth( bool Up ) {
931 OT->SLOT_SetEnabled( Up );
932}
933
934void OTMain::SLOT_DeviceIsEnabled( bool Up ) {
935 MustBeEnabled_CB->blockSignals( TRUE );
936 MustBeEnabled_CB->setChecked( Up );
937 MustBeEnabled_CB->blockSignals( FALSE );
938}
939
940void OTMain::SLOT_Manage( void ) {
941 QDialog * Dlg = new QDialog( this, 0, TRUE );
942 QVBoxLayout * V = new QVBoxLayout( Dlg );
943 OTManage * Mng = new OTManage( Dlg, Icons );
944
945 V->addWidget( Mng );
946
947 Dlg->setCaption( tr("Manage local devices" ) );
948 Dlg->showMaximized();
949 Dlg->exec();
950 delete Dlg;
951}
952
953void OTMain::SLOT_Scan( void ) {
954 OTDriverList & DL = OT->getDriverList();
955 for( unsigned int i = 0;
956 i < DL.count();
957 i ++ ) {
958 if( DL[i]->isUp() &&
959 DL[i]->devname() == DeviceList_CB->currentText()
960 ) {
961 QDialog * Dlg = new QDialog( this, 0, TRUE );
962 QVBoxLayout * V = new QVBoxLayout( Dlg );
963 OTScan * Scn = new OTScan( Dlg, Icons );
964
965 OT->setScanWith( OT->driver(i) );
966 V->addWidget( Scn );
967 Dlg->setCaption( tr("Scan Neighbourhood" ) );
968 Dlg->showMaximized();
969 Dlg->exec();
970
971 delete Dlg;
972 return;
973 }
974 }
975
976}
977
978void OTMain::SLOT_StateChange( OTDriver * D, bool Up ) {
979 for( int i = 0;
980 i < DeviceList_CB->count();
981 i ++ ) {
982 if( DeviceList_CB->text(i) == D->devname() ) {
983 DeviceList_CB->changeItem(
984 Icons->loadPixmap( (Up) ? "bluezon" : "bluezoff" ),
985 D->devname(),
986 i );
987 return;
988 }
989 }
990}
991
992void OTMain::SLOT_Pairing( void ) {
993 QDialog * Dlg = new QDialog( this, 0, TRUE );
994 QVBoxLayout * V = new QVBoxLayout( Dlg );
995 OTPairing * Pair = new OTPairing( Dlg, Icons );
996
997 V->addWidget( Pair );
998 Dlg->showMaximized();
999 Dlg->setCaption( tr("Manage pairing" ) );
1000 Dlg->exec();
1001
1002 delete Dlg;
1003}
diff --git a/noncore/settings/networksettings2/opietooth2/Opietooth.h b/noncore/settings/networksettings2/opietooth2/Opietooth.h
new file mode 100644
index 0000000..9e53fcb
--- a/dev/null
+++ b/noncore/settings/networksettings2/opietooth2/Opietooth.h
@@ -0,0 +1,194 @@
1#ifndef OPIETOOTH_H
2#define OPIETOOTH_H
3
4#include <OTIcons.h>
5
6#include <OTPairingGUI.h>
7class OLedBox;
8
9namespace Opietooth2 {
10
11class OTGateway;
12class OTDriver;
13class OTInquiry;
14class OTPeer;
15class PeerLVI;
16
17class OTPairing : public OTPairingGUI {
18
19 Q_OBJECT
20
21public :
22
23 OTPairing( QWidget * parent,
24 OTIcons * _Ic = 0 );
25 ~OTPairing();
26
27private slots :
28
29 void SLOT_Unpair( void );
30
31signals :
32
33protected :
34
35private :
36
37 bool MyIcons;
38 OTIcons * Icons;
39 OTGateway * OT;
40};
41};
42
43#include <OTScanGUI.h>
44
45namespace Opietooth2 {
46
47class OTGateway;
48class OTDriver;
49class OTInquiry;
50class OTPeer;
51
52class OTScan : public OTScanGUI {
53
54 Q_OBJECT
55
56public :
57
58 OTScan( QWidget * parent,
59 OTIcons * _Ic = 0 );
60 ~OTScan();
61
62 // static function to return a device and a channel
63 static int getDevice( OTPeer *& Peer,
64 int & Channel,
65 OTGateway * OT,
66 const UUIDVector & Filter = 0,
67 QWidget* Parent = 0);
68
69 // show only services that match any of the filter
70 void setScanFilter( const UUIDVector & Filter );
71 void resetScanFilter( void );
72
73 inline OTPeer * selectedPeer( void )
74 { return SelectedPeer; }
75 inline int selectedChannel( void )
76 { return SelectedChannel; }
77
78public slots :
79
80private slots :
81
82 void SLOT_DoScan( bool );
83 void SLOT_NewPeer( OTPeer *, bool );
84 void SLOT_FinishedDetecting();
85 void SLOT_Show( QListViewItem *);
86 void SLOT_RefreshServices( void );
87 void SLOT_RefreshState( void );
88 void SLOT_CleanupOld( void );
89 void SLOT_UpdateStrength( void );
90 void SLOT_PeerState( OTPeer * );
91 void SLOT_Selected( QListViewItem * );
92
93signals :
94
95 void selected( void );
96
97protected :
98
99private :
100
101 void refreshState( PeerLVI *, bool );
102 void scanMode( bool );
103
104 // load scanned devices
105
106 bool MyIcons;
107 OTIcons * Icons;
108 OTGateway * OT;
109 OTInquiry * Scanning;
110 UUIDVector Filter;
111
112 OLedBox * Paired_Led;
113 QTimer * StrengthTimer;
114 PeerLVI * Current;
115
116 OTPeer * SelectedPeer;
117 int SelectedChannel;
118};
119};
120
121#include <OTManageGUI.h>
122namespace Opietooth2 {
123
124class OTManage : public OTManageGUI {
125
126 Q_OBJECT
127
128public :
129
130 OTManage( QWidget * parent,
131 OTIcons * _IC = 0 );
132 ~OTManage();
133
134public slots :
135
136private slots :
137
138 void SLOT_ShowDriver( QListViewItem * );
139 void SLOT_UpDriver( bool );
140 void SLOT_StateChange( OTDriver * , bool );
141 void SLOT_DriverListChanged();
142 void SLOT_SetRefreshTimer( int );
143
144signals :
145
146protected :
147
148private :
149
150 // load scanned devices
151
152 bool MyIcons;
153 OTIcons * Icons;
154 OTGateway * OT;
155 OTInquiry * Scanning;
156};
157};
158
159#include <OTMainGUI.h>
160
161namespace Opietooth2 {
162class OTMain : public OTMainGUI {
163
164 Q_OBJECT
165
166public :
167
168 OTMain( QWidget * parent );
169 ~OTMain();
170
171public slots :
172
173private slots :
174
175 void SLOT_Pairing( void );
176 void SLOT_Manage( void );
177 void SLOT_Scan( void );
178 void SLOT_EnableBluetooth( bool );
179 void SLOT_DriverListChanged();
180 void SLOT_DeviceIsEnabled( bool );
181 void SLOT_StateChange( OTDriver * , bool );
182
183signals :
184
185protected :
186
187private :
188
189 // load scanned devices
190 OTIcons * Icons;
191 OTGateway * OT;
192};
193};
194#endif
diff --git a/noncore/settings/networksettings2/opietooth2/bluezlib.h b/noncore/settings/networksettings2/opietooth2/bluezlib.h
new file mode 100644
index 0000000..c431574
--- a/dev/null
+++ b/noncore/settings/networksettings2/opietooth2/bluezlib.h
@@ -0,0 +1,28 @@
1#ifndef BLUEZLIB_H
2#define BLUEZLIB_H
3
4#include <signal.h>
5#include <errno.h>
6#include <sys/ioctl.h>
7#include <sys/socket.h>
8#include <fcntl.h>
9#include <unistd.h>
10#include <stdlib.h>
11
12extern "C" {
13#include <bluetooth/bluetooth.h>
14#include <bluetooth/hci.h>
15#include <bluetooth/hci_lib.h>
16#include <bluetooth/sdp.h>
17#include <bluetooth/sdp_lib.h>
18#include <bluetooth/l2cap.h>
19#include <bluetooth/bnep.h>
20#include <bluetooth/rfcomm.h>
21}
22
23#define BT_DISABLED 0
24#define BT_ENABLED 1
25#define BT_UNKNOWN 2
26#define BTVALUE(x) ((x)?BT_ENABLED:BT_DISABLED)
27
28#endif
diff --git a/noncore/settings/networksettings2/opietooth2/config.in b/noncore/settings/networksettings2/opietooth2/config.in
new file mode 100644
index 0000000..720f49a
--- a/dev/null
+++ b/noncore/settings/networksettings2/opietooth2/config.in
@@ -0,0 +1,5 @@
1config NS2OPIETOOTH
2 boolean "opie-networksettings2 bluetooth library"
3 default "y"
4 depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE2CORE
5
diff --git a/noncore/settings/networksettings2/opietooth2/libopietooth2.control b/noncore/settings/networksettings2/opietooth2/libopietooth2.control
new file mode 100644
index 0000000..fd01fb5
--- a/dev/null
+++ b/noncore/settings/networksettings2/opietooth2/libopietooth2.control
@@ -0,0 +1,9 @@
1Package: libopietooth2
2Files: lib/libopietooth2.so.* apps/Settings/opietooth-manager.desktop pics/opietooth/*.png pics/opietooth/icons/*.png
3Priority: optional
4Section: opie/system
5Maintainer: wim delvaux <wim.delvaux@handhelds.org>
6Architecture: arm
7Version: $QPE_VERSION$EXTRAVERSION
8Depends: task-opie-minimal, libbluetooth1, opie-bluepin | opie-multiauth-bluepingplugin, bluez-utils-nodbus
9Description: Opie bluetooth support library version 2
diff --git a/noncore/settings/networksettings2/opietooth2/libopietooth2.postinst b/noncore/settings/networksettings2/opietooth2/libopietooth2.postinst
new file mode 100755
index 0000000..cd605c2
--- a/dev/null
+++ b/noncore/settings/networksettings2/opietooth2/libopietooth2.postinst
@@ -0,0 +1,10 @@
1#!/bin/sh
2
3QTPB=/opt/QtPalmtop/bin
4
5[ ! -L ${QTPB}/networksettings2-opietooth ] && ln -sf ${QTPB}/networksettings2 ${QTPB}/networksettings2-opietooth
6
7# qcop QPE/Taskbar "linkChanged(opietooth)"
8qcop QPE/Taskbar "reloadApps()"
9
10exit 0
diff --git a/noncore/settings/networksettings2/opietooth2/opietooth2.pro b/noncore/settings/networksettings2/opietooth2/opietooth2.pro
new file mode 100644
index 0000000..590b656
--- a/dev/null
+++ b/noncore/settings/networksettings2/opietooth2/opietooth2.pro
@@ -0,0 +1,37 @@
1TEMPLATE = lib
2CONFIG += qt warn_on release
3 #CONFIG += qt warn_on debug
4 DESTDIR = $(OPIEDIR)/lib$(PROJMAK)
5 HEADERS = OTDevice.h \
6 OTDriver.h \
7 OTGateway.h \
8 OTHCISocket.h \
9 OTInquiry.h \
10 OTDeviceAddress.h \
11 OTIcons.h \
12 OTUUID.h \
13 OTSDPAttribute.h \
14 OTSDPService.h \
15 OTPeer.h \
16 Opietooth.h
17 SOURCES = OTDevice.cpp \
18 OTDriver.cpp \
19 OTDriverList.cpp \
20 OTHCISocket.cpp \
21 OTInquiry.cpp \
22 OTDeviceAddress.cpp \
23 OTUUID.cpp \
24 OTSDPAttribute.cpp \
25 OTSDPService.cpp \
26 OTIcons.cpp \
27 OTPeer.cpp \
28 OTGateway.cpp \
29 Opietooth.cpp
30 INCLUDEPATH+= $(OPIEDIR)/include
31 DEPENDPATH+= $(OPIEDIR)/include
32LIBS += -lqpe -lopiecore2 -lbluetooth
33 INTERFACES= OTMainGUI.ui OTScanGUI.ui OTManageGUI.ui OTPairingGUI.ui
34 TARGET = opietooth2
35 VERSION = 1.0.0
36
37include ( $(OPIEDIR)/include.pro )