author | mickeyl <mickeyl> | 2005-05-03 14:06:40 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2005-05-03 14:06:40 (UTC) |
commit | a0da10e78110fe3b291f4d2d3956bf6003ca2d2a (patch) (unidiff) | |
tree | 8b902cdc88d4c196971c7a925aa3e7dfc2215c54 | |
parent | 8dc5378786b26d847e4771129760ccb76f04c40f (diff) | |
download | opie-a0da10e78110fe3b291f4d2d3956bf6003ca2d2a.zip opie-a0da10e78110fe3b291f4d2d3956bf6003ca2d2a.tar.gz opie-a0da10e78110fe3b291f4d2d3956bf6003ca2d2a.tar.bz2 |
GET_LINK_QUALITY_RP_SIZE has been renamed to READ_LINK_QUALITY_RP_SIZE in newer versions of bluez
-rw-r--r-- | noncore/settings/networksettings2/opietooth2/OTDriver.cpp | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/noncore/settings/networksettings2/opietooth2/OTDriver.cpp b/noncore/settings/networksettings2/opietooth2/OTDriver.cpp index cfd0491..dbc9b97 100644 --- a/noncore/settings/networksettings2/opietooth2/OTDriver.cpp +++ b/noncore/settings/networksettings2/opietooth2/OTDriver.cpp | |||
@@ -1,744 +1,746 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * Copyright (C) 2003 by Mattia Merzi * | 2 | * Copyright (C) 2003 by Mattia Merzi * |
3 | * ottobit@ferrara.linux.it * | 3 | * ottobit@ferrara.linux.it * |
4 | * * | 4 | * * |
5 | * This program is free software; you can redistribute it and/or modify * | 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 * | 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 * | 7 | * the Free Software Foundation; either version 2 of the License, or * |
8 | * (at your option) any later version. * | 8 | * (at your option) any later version. * |
9 | ***************************************************************************/ | 9 | ***************************************************************************/ |
10 | 10 | ||
11 | #include <opie2/odebug.h> | 11 | #include <opie2/odebug.h> |
12 | #include <qtimer.h> | 12 | #include <qtimer.h> |
13 | 13 | ||
14 | #include <sys/poll.h> | 14 | #include <sys/poll.h> |
15 | #include <bluezlib.h> | 15 | #include <bluezlib.h> |
16 | 16 | #ifndef GET_LINK_QUALITY_RP_SIZE | |
17 | #define GET_LINK_QUALITY_RP_SIZE READ_LINK_QUALITY_RP_SIZE | ||
18 | #endif | ||
17 | #include <OTGateway.h> | 19 | #include <OTGateway.h> |
18 | #include <OTDriver.h> | 20 | #include <OTDriver.h> |
19 | #include <OTHCISocket.h> | 21 | #include <OTHCISocket.h> |
20 | 22 | ||
21 | using namespace Opietooth2; | 23 | using namespace Opietooth2; |
22 | 24 | ||
23 | static struct { | 25 | static struct { |
24 | const char *str; | 26 | const char *str; |
25 | unsigned short rev; | 27 | unsigned short rev; |
26 | } csr_map[] = { | 28 | } csr_map[] = { |
27 | { "HCI 11.2 (bc01b)", 114 }, | 29 | { "HCI 11.2 (bc01b)", 114 }, |
28 | { "HCI 11.3 (bc01b)", 115 }, | 30 | { "HCI 11.3 (bc01b)", 115 }, |
29 | { "HCI 12.1 (bc01b)", 119 }, | 31 | { "HCI 12.1 (bc01b)", 119 }, |
30 | { "HCI 12.3 (bc01b)", 134 }, | 32 | { "HCI 12.3 (bc01b)", 134 }, |
31 | { "HCI 12.7 (bc01b)", 188 }, | 33 | { "HCI 12.7 (bc01b)", 188 }, |
32 | { "HCI 12.8 (bc01b)", 218 }, | 34 | { "HCI 12.8 (bc01b)", 218 }, |
33 | { "HCI 12.9 (bc01b)", 283 }, | 35 | { "HCI 12.9 (bc01b)", 283 }, |
34 | { "HCI 13.10 (bc01b)", 309 }, | 36 | { "HCI 13.10 (bc01b)", 309 }, |
35 | { "HCI 13.11 (bc01b)", 351 }, | 37 | { "HCI 13.11 (bc01b)", 351 }, |
36 | { "HCI 16.4 (bc01b)", 523 }, | 38 | { "HCI 16.4 (bc01b)", 523 }, |
37 | { "HCI 14.3 (bc02x)", 272 }, | 39 | { "HCI 14.3 (bc02x)", 272 }, |
38 | { "HCI 14.6 (bc02x)", 336 }, | 40 | { "HCI 14.6 (bc02x)", 336 }, |
39 | { "HCI 14.7 (bc02x)", 373 }, | 41 | { "HCI 14.7 (bc02x)", 373 }, |
40 | { "HCI 14.8 (bc02x)", 487 }, | 42 | { "HCI 14.8 (bc02x)", 487 }, |
41 | { "HCI 15.3 (bc02x)", 443 }, | 43 | { "HCI 15.3 (bc02x)", 443 }, |
42 | { "HCI 16.4 (bc02x)", 525 }, | 44 | { "HCI 16.4 (bc02x)", 525 }, |
43 | { NULL, 0} | 45 | { NULL, 0} |
44 | }; | 46 | }; |
45 | 47 | ||
46 | static char *services[] = { "Positioning", | 48 | static char *services[] = { "Positioning", |
47 | "Networking", | 49 | "Networking", |
48 | "Rendering", | 50 | "Rendering", |
49 | "Capturing", | 51 | "Capturing", |
50 | "Object Transfer", | 52 | "Object Transfer", |
51 | "Audio", | 53 | "Audio", |
52 | "Telephony", | 54 | "Telephony", |
53 | "Information" }; | 55 | "Information" }; |
54 | 56 | ||
55 | static char *major_devices[] = { "Miscellaneous", | 57 | static char *major_devices[] = { "Miscellaneous", |
56 | "Computer", | 58 | "Computer", |
57 | "Phone", | 59 | "Phone", |
58 | "LAN Access", | 60 | "LAN Access", |
59 | "Audio/Video", | 61 | "Audio/Video", |
60 | "Peripheral", | 62 | "Peripheral", |
61 | "Imaging", | 63 | "Imaging", |
62 | "Uncategorized" }; | 64 | "Uncategorized" }; |
63 | 65 | ||
64 | 66 | ||
65 | typedef struct { | 67 | typedef struct { |
66 | short Minor; | 68 | short Minor; |
67 | const char * Description; | 69 | const char * Description; |
68 | } ClassMap_t; | 70 | } ClassMap_t; |
69 | 71 | ||
70 | static ClassMap_t MapMiscClass[] = { | 72 | static ClassMap_t MapMiscClass[] = { |
71 | { -1, "" } | 73 | { -1, "" } |
72 | }; | 74 | }; |
73 | 75 | ||
74 | static ClassMap_t MapUnclassifiedClass[] = { | 76 | static ClassMap_t MapUnclassifiedClass[] = { |
75 | { -1, "" } | 77 | { -1, "" } |
76 | }; | 78 | }; |
77 | 79 | ||
78 | static ClassMap_t MapComputerClass[] = { | 80 | static ClassMap_t MapComputerClass[] = { |
79 | { 0, "Uncategorized" } , | 81 | { 0, "Uncategorized" } , |
80 | { 1, "Desktop workstation" } , | 82 | { 1, "Desktop workstation" } , |
81 | { 2, "Server" } , | 83 | { 2, "Server" } , |
82 | { 3, "Laptop" } , | 84 | { 3, "Laptop" } , |
83 | { 4, "Handheld" } , | 85 | { 4, "Handheld" } , |
84 | { 5, "Palm" } , | 86 | { 5, "Palm" } , |
85 | { 6, "Wearable" }, | 87 | { 6, "Wearable" }, |
86 | { -1, 0 } | 88 | { -1, 0 } |
87 | }; | 89 | }; |
88 | 90 | ||
89 | static ClassMap_t MapPhoneClass[] = { | 91 | static ClassMap_t MapPhoneClass[] = { |
90 | { 0, "Uncategorized" }, | 92 | { 0, "Uncategorized" }, |
91 | { 1, "Cellular" }, | 93 | { 1, "Cellular" }, |
92 | { 2, "Cordless" }, | 94 | { 2, "Cordless" }, |
93 | { 3, "Smart phone" }, | 95 | { 3, "Smart phone" }, |
94 | { 4, "Wired modem or voice gateway" }, | 96 | { 4, "Wired modem or voice gateway" }, |
95 | { 5, "Common ISDN Access" }, | 97 | { 5, "Common ISDN Access" }, |
96 | { 6, "Sim Card Reader" }, | 98 | { 6, "Sim Card Reader" }, |
97 | { -1, 0 } | 99 | { -1, 0 } |
98 | }; | 100 | }; |
99 | 101 | ||
100 | static ClassMap_t MapAVClass[] = { | 102 | static ClassMap_t MapAVClass[] = { |
101 | { 0, "Uncategorized" }, | 103 | { 0, "Uncategorized" }, |
102 | { 1, "Device conforms to the Headset profile" }, | 104 | { 1, "Device conforms to the Headset profile" }, |
103 | { 2, "Hands-free" }, | 105 | { 2, "Hands-free" }, |
104 | { 3, 0 }, | 106 | { 3, 0 }, |
105 | { 4, "Microphone" }, | 107 | { 4, "Microphone" }, |
106 | { 5, "Loudspeaker" }, | 108 | { 5, "Loudspeaker" }, |
107 | { 6, "Headphones" }, | 109 | { 6, "Headphones" }, |
108 | { 7, "Portable Audio" }, | 110 | { 7, "Portable Audio" }, |
109 | { 8, "Car Audio" }, | 111 | { 8, "Car Audio" }, |
110 | { 9, "Set-top box" }, | 112 | { 9, "Set-top box" }, |
111 | { 10, "HiFi Audio Device" }, | 113 | { 10, "HiFi Audio Device" }, |
112 | { 11, "VCR" }, | 114 | { 11, "VCR" }, |
113 | { 12, "Video Camera" }, | 115 | { 12, "Video Camera" }, |
114 | { 13, "Camcorder" }, | 116 | { 13, "Camcorder" }, |
115 | { 14, "Video Monitor" }, | 117 | { 14, "Video Monitor" }, |
116 | { 15, "Video Display and Loudspeaker" }, | 118 | { 15, "Video Display and Loudspeaker" }, |
117 | { 16, "Video Conferencing" }, | 119 | { 16, "Video Conferencing" }, |
118 | { 17, 0 }, | 120 | { 17, 0 }, |
119 | { 18, "Gaming/Toy" }, | 121 | { 18, "Gaming/Toy" }, |
120 | { -1, 0 } | 122 | { -1, 0 } |
121 | }; | 123 | }; |
122 | 124 | ||
123 | static ClassMap_t MapPeripheralClass[] = { | 125 | static ClassMap_t MapPeripheralClass[] = { |
124 | { 16, "Keyboard" }, | 126 | { 16, "Keyboard" }, |
125 | { 32, "Pointing device" }, | 127 | { 32, "Pointing device" }, |
126 | { 48, "Combo keyboard/pointing device" }, | 128 | { 48, "Combo keyboard/pointing device" }, |
127 | { -1, 0 } | 129 | { -1, 0 } |
128 | }; | 130 | }; |
129 | 131 | ||
130 | typedef struct { | 132 | typedef struct { |
131 | int Major; | 133 | int Major; |
132 | ClassMap_t * Map; | 134 | ClassMap_t * Map; |
133 | } MainClassMap_t; | 135 | } MainClassMap_t; |
134 | 136 | ||
135 | static MainClassMap_t MainClasses[] = { | 137 | static MainClassMap_t MainClasses[] = { |
136 | { 0, MapMiscClass }, | 138 | { 0, MapMiscClass }, |
137 | { 1, MapComputerClass }, | 139 | { 1, MapComputerClass }, |
138 | { 2, MapPhoneClass }, | 140 | { 2, MapPhoneClass }, |
139 | { 3, 0 }, // special case | 141 | { 3, 0 }, // special case |
140 | { 4, MapAVClass }, | 142 | { 4, MapAVClass }, |
141 | { 5, MapPeripheralClass }, | 143 | { 5, MapPeripheralClass }, |
142 | { 6, 0 }, // special case | 144 | { 6, 0 }, // special case |
143 | { 63, MapUnclassifiedClass }, | 145 | { 63, MapUnclassifiedClass }, |
144 | { -1, 0 } | 146 | { -1, 0 } |
145 | }; | 147 | }; |
146 | 148 | ||
147 | OTDriver::OTDriver( OTGateway * _OT, struct hci_dev_info* di) : QObject( _OT ), Address() { | 149 | OTDriver::OTDriver( OTGateway * _OT, struct hci_dev_info* di) : QObject( _OT ), Address() { |
148 | OT = _OT; | 150 | OT = _OT; |
149 | IsUp = 0; | 151 | IsUp = 0; |
150 | Socket = 0; | 152 | Socket = 0; |
151 | 153 | ||
152 | init(di); | 154 | init(di); |
153 | odebug << "Driver " << devname() << oendl; | 155 | odebug << "Driver " << devname() << oendl; |
154 | 156 | ||
155 | AutoClose = new QTimer( this ); | 157 | AutoClose = new QTimer( this ); |
156 | connect( AutoClose, | 158 | connect( AutoClose, |
157 | SIGNAL( timeout() ), | 159 | SIGNAL( timeout() ), |
158 | this, | 160 | this, |
159 | SLOT( SLOT_CloseFd() ) | 161 | SLOT( SLOT_CloseFd() ) |
160 | ); | 162 | ); |
161 | } | 163 | } |
162 | 164 | ||
163 | OTDriver::~OTDriver() { | 165 | OTDriver::~OTDriver() { |
164 | closeSocket(); | 166 | closeSocket(); |
165 | SLOT_CloseFd(); | 167 | SLOT_CloseFd(); |
166 | } | 168 | } |
167 | 169 | ||
168 | void OTDriver::SLOT_CloseFd( void ){ | 170 | void OTDriver::SLOT_CloseFd( void ){ |
169 | if ( isOpen() ) { | 171 | if ( isOpen() ) { |
170 | AutoClose->stop(); | 172 | AutoClose->stop(); |
171 | ::close( fd() ); | 173 | ::close( fd() ); |
172 | setfd( -1 ); | 174 | setfd( -1 ); |
173 | } | 175 | } |
174 | } | 176 | } |
175 | 177 | ||
176 | void OTDriver::init(struct hci_dev_info* di) { | 178 | void OTDriver::init(struct hci_dev_info* di) { |
177 | 179 | ||
178 | Dev = di->name; | 180 | Dev = di->name; |
179 | 181 | ||
180 | setDevId(di->dev_id); | 182 | setDevId(di->dev_id); |
181 | setType(di->type); | 183 | setType(di->type); |
182 | setFlags(di->flags); | 184 | setFlags(di->flags); |
183 | Address.setBDAddr( di->bdaddr ); | 185 | Address.setBDAddr( di->bdaddr ); |
184 | setFeatures(di->features); | 186 | setFeatures(di->features); |
185 | setfd( -1 ); // not open | 187 | setfd( -1 ); // not open |
186 | 188 | ||
187 | Manufacturer = ""; | 189 | Manufacturer = ""; |
188 | } | 190 | } |
189 | 191 | ||
190 | // internal reinitialize | 192 | // internal reinitialize |
191 | void OTDriver::reinit() { | 193 | void OTDriver::reinit() { |
192 | bool Old; | 194 | bool Old; |
193 | Old = IsUp; | 195 | Old = IsUp; |
194 | 196 | ||
195 | if( currentState() < 0 ) | 197 | if( currentState() < 0 ) |
196 | return; | 198 | return; |
197 | 199 | ||
198 | if( Old != IsUp ) { | 200 | if( Old != IsUp ) { |
199 | // state changes | 201 | // state changes |
200 | emit stateChange( this, IsUp ); | 202 | emit stateChange( this, IsUp ); |
201 | } | 203 | } |
202 | } | 204 | } |
203 | 205 | ||
204 | // requested by application | 206 | // requested by application |
205 | int OTDriver::currentState() { | 207 | int OTDriver::currentState() { |
206 | struct hci_dev_info di; | 208 | struct hci_dev_info di; |
207 | 209 | ||
208 | // uint16_t tmp_dev_id = device_info.dev_id; | 210 | // uint16_t tmp_dev_id = device_info.dev_id; |
209 | // bzero(&device_info,sizeof(struct hci_dev_info)); | 211 | // bzero(&device_info,sizeof(struct hci_dev_info)); |
210 | // device_info.dev_id = tmp_dev_id; | 212 | // device_info.dev_id = tmp_dev_id; |
211 | 213 | ||
212 | memset( &di, 0, sizeof( di ) ); | 214 | memset( &di, 0, sizeof( di ) ); |
213 | di.dev_id = Dev_id; | 215 | di.dev_id = Dev_id; |
214 | if( ioctl( OT->getSocket(), HCIGETDEVINFO, (void*)&di) < 0 ) { | 216 | if( ioctl( OT->getSocket(), HCIGETDEVINFO, (void*)&di) < 0 ) { |
215 | SLOT_CloseFd(); | 217 | SLOT_CloseFd(); |
216 | return -1; | 218 | return -1; |
217 | } else { | 219 | } else { |
218 | // load new info | 220 | // load new info |
219 | init(&di); | 221 | init(&di); |
220 | } | 222 | } |
221 | 223 | ||
222 | return IsUp; | 224 | return IsUp; |
223 | } | 225 | } |
224 | 226 | ||
225 | bool OTDriver::open() { | 227 | bool OTDriver::open() { |
226 | 228 | ||
227 | // (re)start single shot close | 229 | // (re)start single shot close |
228 | AutoClose->start( 30000, TRUE ); | 230 | AutoClose->start( 30000, TRUE ); |
229 | 231 | ||
230 | if( isOpen() ) | 232 | if( isOpen() ) |
231 | // is open | 233 | // is open |
232 | return 1; | 234 | return 1; |
233 | 235 | ||
234 | setfd(hci_open_dev(devId())); | 236 | setfd(hci_open_dev(devId())); |
235 | 237 | ||
236 | if (fd() < 0) { | 238 | if (fd() < 0) { |
237 | emit error( tr( "Can't open device %1. %2 : %3" ). | 239 | emit error( tr( "Can't open device %1. %2 : %3" ). |
238 | arg( devname() ). | 240 | arg( devname() ). |
239 | arg( errno ). | 241 | arg( errno ). |
240 | arg( strerror(errno) ) | 242 | arg( strerror(errno) ) |
241 | ); | 243 | ); |
242 | return 0; | 244 | return 0; |
243 | } | 245 | } |
244 | 246 | ||
245 | return 1; | 247 | return 1; |
246 | } | 248 | } |
247 | 249 | ||
248 | QString OTDriver::name() { | 250 | QString OTDriver::name() { |
249 | char name[1000]; | 251 | char name[1000]; |
250 | 252 | ||
251 | if( ! open() ) { | 253 | if( ! open() ) { |
252 | return tr("Cannot open"); | 254 | return tr("Cannot open"); |
253 | } | 255 | } |
254 | 256 | ||
255 | if (hci_read_local_name( fd(), sizeof(name), name, 1000) < 0) { | 257 | if (hci_read_local_name( fd(), sizeof(name), name, 1000) < 0) { |
256 | if (errno != ETIMEDOUT) { | 258 | if (errno != ETIMEDOUT) { |
257 | emit error( tr("Can't read local name on %1. %2 : %3. Default to %4" ). | 259 | emit error( tr("Can't read local name on %1. %2 : %3. Default to %4" ). |
258 | arg( devname() ). | 260 | arg( devname() ). |
259 | arg( errno ). | 261 | arg( errno ). |
260 | arg( strerror(errno) ). | 262 | arg( strerror(errno) ). |
261 | arg( devname() ) | 263 | arg( devname() ) |
262 | ); | 264 | ); |
263 | } // ETIMEDOUT error is quite normal, device is down ... I think ! :) | 265 | } // ETIMEDOUT error is quite normal, device is down ... I think ! :) |
264 | strcpy(name,devname().latin1()); | 266 | strcpy(name,devname().latin1()); |
265 | } | 267 | } |
266 | return QString(name); | 268 | return QString(name); |
267 | } | 269 | } |
268 | 270 | ||
269 | void OTDriver::setFlags(unsigned long flags) { | 271 | void OTDriver::setFlags(unsigned long flags) { |
270 | 272 | ||
271 | // kdDebug() << "Setting OTDriver Values ..." << endl; | 273 | // kdDebug() << "Setting OTDriver Values ..." << endl; |
272 | IsUp = BTVALUE(hci_test_bit(HCI_UP, &flags)); | 274 | IsUp = BTVALUE(hci_test_bit(HCI_UP, &flags)); |
273 | 275 | ||
274 | if (isUp()) { | 276 | if (isUp()) { |
275 | setIScan(BTVALUE(hci_test_bit(HCI_ISCAN, &flags))); | 277 | setIScan(BTVALUE(hci_test_bit(HCI_ISCAN, &flags))); |
276 | setPScan(BTVALUE(hci_test_bit(HCI_PSCAN, &flags))); | 278 | setPScan(BTVALUE(hci_test_bit(HCI_PSCAN, &flags))); |
277 | setAuthentication(BTVALUE(hci_test_bit(HCI_AUTH, &flags))); | 279 | setAuthentication(BTVALUE(hci_test_bit(HCI_AUTH, &flags))); |
278 | setEncryption(BTVALUE(hci_test_bit(HCI_ENCRYPT, &flags))); | 280 | setEncryption(BTVALUE(hci_test_bit(HCI_ENCRYPT, &flags))); |
279 | } else { | 281 | } else { |
280 | setIScan(BT_UNKNOWN); | 282 | setIScan(BT_UNKNOWN); |
281 | setPScan(BT_UNKNOWN); | 283 | setPScan(BT_UNKNOWN); |
282 | setAuthentication(BT_UNKNOWN); | 284 | setAuthentication(BT_UNKNOWN); |
283 | setEncryption(BT_UNKNOWN); | 285 | setEncryption(BT_UNKNOWN); |
284 | } | 286 | } |
285 | } | 287 | } |
286 | 288 | ||
287 | QString OTDriver::revision() { | 289 | QString OTDriver::revision() { |
288 | 290 | ||
289 | struct hci_version ver; | 291 | struct hci_version ver; |
290 | 292 | ||
291 | if( ! open() ) { | 293 | if( ! open() ) { |
292 | return tr("Cannot open"); | 294 | return tr("Cannot open"); |
293 | } | 295 | } |
294 | 296 | ||
295 | if (hci_read_local_version(fd(), &ver, 1000) < 0) { | 297 | if (hci_read_local_version(fd(), &ver, 1000) < 0) { |
296 | emit error( tr( "Can't read revision info on %1. %2 : %3" ). | 298 | emit error( tr( "Can't read revision info on %1. %2 : %3" ). |
297 | arg( devname() ). | 299 | arg( devname() ). |
298 | arg( errno ). | 300 | arg( errno ). |
299 | arg( strerror(errno) ) ); | 301 | arg( strerror(errno) ) ); |
300 | return QString(); | 302 | return QString(); |
301 | } | 303 | } |
302 | 304 | ||
303 | setManufacturer(ver.manufacturer); | 305 | setManufacturer(ver.manufacturer); |
304 | 306 | ||
305 | switch (ver.manufacturer) { | 307 | switch (ver.manufacturer) { |
306 | case 0: | 308 | case 0: |
307 | return getRevEricsson(); | 309 | return getRevEricsson(); |
308 | break; | 310 | break; |
309 | case 10: | 311 | case 10: |
310 | return getRevCsr(ver.hci_rev); | 312 | return getRevCsr(ver.hci_rev); |
311 | break; | 313 | break; |
312 | default: | 314 | default: |
313 | return tr( "Unsupported manufacturer" ); | 315 | return tr( "Unsupported manufacturer" ); |
314 | break; | 316 | break; |
315 | } | 317 | } |
316 | } | 318 | } |
317 | 319 | ||
318 | QString OTDriver::getRevEricsson() { | 320 | QString OTDriver::getRevEricsson() { |
319 | 321 | ||
320 | char revision[102]; | 322 | char revision[102]; |
321 | struct hci_request rq; | 323 | struct hci_request rq; |
322 | 324 | ||
323 | if( ! open() ) { | 325 | if( ! open() ) { |
324 | return QString( "Cannot open" ); | 326 | return QString( "Cannot open" ); |
325 | } | 327 | } |
326 | 328 | ||
327 | memset(&rq, 0, sizeof(rq)); | 329 | memset(&rq, 0, sizeof(rq)); |
328 | rq.ogf = 0x3f; | 330 | rq.ogf = 0x3f; |
329 | rq.ocf = 0x000f; | 331 | rq.ocf = 0x000f; |
330 | rq.cparam = NULL; | 332 | rq.cparam = NULL; |
331 | rq.clen = 0; | 333 | rq.clen = 0; |
332 | rq.rparam = &revision; | 334 | rq.rparam = &revision; |
333 | rq.rlen = sizeof(revision); | 335 | rq.rlen = sizeof(revision); |
334 | 336 | ||
335 | if (hci_send_req(fd(), &rq, 1000) < 0) { | 337 | if (hci_send_req(fd(), &rq, 1000) < 0) { |
336 | emit error( tr( "Can't read revision info on %1. %2 : %3" ). | 338 | emit error( tr( "Can't read revision info on %1. %2 : %3" ). |
337 | arg( devname() ). | 339 | arg( devname() ). |
338 | arg( errno ). | 340 | arg( errno ). |
339 | arg( strerror(errno) ) ); | 341 | arg( strerror(errno) ) ); |
340 | return QString(); | 342 | return QString(); |
341 | } | 343 | } |
342 | 344 | ||
343 | return QString( revision+1 ); | 345 | return QString( revision+1 ); |
344 | } | 346 | } |
345 | 347 | ||
346 | QString OTDriver::getRevCsr( unsigned short rev) { | 348 | QString OTDriver::getRevCsr( unsigned short rev) { |
347 | 349 | ||
348 | int i; | 350 | int i; |
349 | 351 | ||
350 | for (i = 0; csr_map[i].str; i++) | 352 | for (i = 0; csr_map[i].str; i++) |
351 | if (csr_map[i].rev == rev) { | 353 | if (csr_map[i].rev == rev) { |
352 | return QString( csr_map[i].str ); | 354 | return QString( csr_map[i].str ); |
353 | } | 355 | } |
354 | 356 | ||
355 | return tr( "Unknown firmware" ); | 357 | return tr( "Unknown firmware" ); |
356 | } | 358 | } |
357 | 359 | ||
358 | int OTDriver::reset() { | 360 | int OTDriver::reset() { |
359 | 361 | ||
360 | if( ! open() ) { | 362 | if( ! open() ) { |
361 | return 0; | 363 | return 0; |
362 | } | 364 | } |
363 | 365 | ||
364 | if( ioctl(fd(), HCIDEVRESET, devId()) < 0 ) { | 366 | if( ioctl(fd(), HCIDEVRESET, devId()) < 0 ) { |
365 | if( errno != EALREADY ) { | 367 | if( errno != EALREADY ) { |
366 | emit error( tr( "Reset failed for %1. %2 : %3" ). | 368 | emit error( tr( "Reset failed for %1. %2 : %3" ). |
367 | arg( devname() ). | 369 | arg( devname() ). |
368 | arg( errno ). | 370 | arg( errno ). |
369 | arg( strerror(errno) ) ); | 371 | arg( strerror(errno) ) ); |
370 | if (errno == EACCES) { | 372 | if (errno == EACCES) { |
371 | return EACCES; | 373 | return EACCES; |
372 | } | 374 | } |
373 | } | 375 | } |
374 | } | 376 | } |
375 | return 0; | 377 | return 0; |
376 | } | 378 | } |
377 | 379 | ||
378 | void OTDriver::setUp( bool M ) { | 380 | void OTDriver::setUp( bool M ) { |
379 | if( M && ! isUp() ) { | 381 | if( M && ! isUp() ) { |
380 | bringUp(); | 382 | bringUp(); |
381 | } else if( ! M && isUp() ) { | 383 | } else if( ! M && isUp() ) { |
382 | bringDown(); | 384 | bringDown(); |
383 | } | 385 | } |
384 | } | 386 | } |
385 | 387 | ||
386 | void OTDriver::bringUp() { | 388 | void OTDriver::bringUp() { |
387 | 389 | ||
388 | odebug << "bringUp : " << Dev << oendl; | 390 | odebug << "bringUp : " << Dev << oendl; |
389 | 391 | ||
390 | if( ! open() ) { | 392 | if( ! open() ) { |
391 | return; | 393 | return; |
392 | } | 394 | } |
393 | 395 | ||
394 | if (! isUp()) { | 396 | if (! isUp()) { |
395 | if( ioctl(fd(), HCIDEVUP, devId()) < 0 ) { | 397 | if( ioctl(fd(), HCIDEVUP, devId()) < 0 ) { |
396 | if( errno != EALREADY ) { | 398 | if( errno != EALREADY ) { |
397 | emit error( tr( "Cannot bring interface %1 up. %2 : %3" ). | 399 | emit error( tr( "Cannot bring interface %1 up. %2 : %3" ). |
398 | arg( devname() ). | 400 | arg( devname() ). |
399 | arg( errno ). | 401 | arg( errno ). |
400 | arg( strerror(errno) ) ); | 402 | arg( strerror(errno) ) ); |
401 | } | 403 | } |
402 | return; | 404 | return; |
403 | } | 405 | } |
404 | // have to wait a bit for the 'up' to become active | 406 | // have to wait a bit for the 'up' to become active |
405 | QTimer::singleShot( 3000, this, SLOT( reinit() ) ); | 407 | QTimer::singleShot( 3000, this, SLOT( reinit() ) ); |
406 | } | 408 | } |
407 | } | 409 | } |
408 | 410 | ||
409 | void OTDriver::bringDown() { | 411 | void OTDriver::bringDown() { |
410 | 412 | ||
411 | odebug << "bringDown : " << Dev << oendl; | 413 | odebug << "bringDown : " << Dev << oendl; |
412 | 414 | ||
413 | if( ! open() ) { | 415 | if( ! open() ) { |
414 | return; | 416 | return; |
415 | } | 417 | } |
416 | 418 | ||
417 | if ( isUp() ) { | 419 | if ( isUp() ) { |
418 | if( ioctl(fd(), HCIDEVDOWN, devId()) < 0 ) { | 420 | if( ioctl(fd(), HCIDEVDOWN, devId()) < 0 ) { |
419 | if( errno != EALREADY ) { | 421 | if( errno != EALREADY ) { |
420 | emit error( tr( "Cannot bring interface %1 down. %2 : %3" ). | 422 | emit error( tr( "Cannot bring interface %1 down. %2 : %3" ). |
421 | arg( devname() ). | 423 | arg( devname() ). |
422 | arg( errno ). | 424 | arg( errno ). |
423 | arg( strerror(errno) ) ); | 425 | arg( strerror(errno) ) ); |
424 | } | 426 | } |
425 | return; | 427 | return; |
426 | } | 428 | } |
427 | reinit(); | 429 | reinit(); |
428 | } | 430 | } |
429 | } | 431 | } |
430 | 432 | ||
431 | void OTDriver::setScanMode(bool iscan, bool pscan) { | 433 | void OTDriver::setScanMode(bool iscan, bool pscan) { |
432 | 434 | ||
433 | struct hci_dev_req dr; | 435 | struct hci_dev_req dr; |
434 | 436 | ||
435 | if( ! open() ) { | 437 | if( ! open() ) { |
436 | return; | 438 | return; |
437 | } | 439 | } |
438 | 440 | ||
439 | dr.dev_id = devId(); | 441 | dr.dev_id = devId(); |
440 | dr.dev_opt = SCAN_DISABLED; | 442 | dr.dev_opt = SCAN_DISABLED; |
441 | 443 | ||
442 | if( iscan&&(!pscan) ) | 444 | if( iscan&&(!pscan) ) |
443 | dr.dev_opt = SCAN_INQUIRY; | 445 | dr.dev_opt = SCAN_INQUIRY; |
444 | else if( pscan&&(!iscan) ) | 446 | else if( pscan&&(!iscan) ) |
445 | dr.dev_opt = SCAN_PAGE; | 447 | dr.dev_opt = SCAN_PAGE; |
446 | else if( pscan&&iscan ) | 448 | else if( pscan&&iscan ) |
447 | dr.dev_opt = SCAN_PAGE | SCAN_INQUIRY; | 449 | dr.dev_opt = SCAN_PAGE | SCAN_INQUIRY; |
448 | 450 | ||
449 | if( ioctl(fd(), HCISETSCAN, (unsigned long)&dr) < 0 ) { | 451 | if( ioctl(fd(), HCISETSCAN, (unsigned long)&dr) < 0 ) { |
450 | if( errno != EALREADY ) { | 452 | if( errno != EALREADY ) { |
451 | emit error( tr( "Can't set scan mode on %1. %2 : %3" ). | 453 | emit error( tr( "Can't set scan mode on %1. %2 : %3" ). |
452 | arg( devname() ). | 454 | arg( devname() ). |
453 | arg( errno ). | 455 | arg( errno ). |
454 | arg( strerror(errno) ) ); | 456 | arg( strerror(errno) ) ); |
455 | } | 457 | } |
456 | return; | 458 | return; |
457 | } | 459 | } |
458 | 460 | ||
459 | reinit(); | 461 | reinit(); |
460 | } | 462 | } |
461 | 463 | ||
462 | void OTDriver::changeDevName(const char* name) { | 464 | void OTDriver::changeDevName(const char* name) { |
463 | 465 | ||
464 | if( ! open() ) { | 466 | if( ! open() ) { |
465 | return; | 467 | return; |
466 | } | 468 | } |
467 | 469 | ||
468 | if (hci_write_local_name(fd(), name, 1000) < 0) { | 470 | if (hci_write_local_name(fd(), name, 1000) < 0) { |
469 | emit error( tr( "Can't change local name on %1. %2 : %3" ). | 471 | emit error( tr( "Can't change local name on %1. %2 : %3" ). |
470 | arg( devname() ). | 472 | arg( devname() ). |
471 | arg( errno ). | 473 | arg( errno ). |
472 | arg( strerror(errno) ) ); | 474 | arg( strerror(errno) ) ); |
473 | } | 475 | } |
474 | } | 476 | } |
475 | 477 | ||
476 | void OTDriver::changeAuthentication(bool _auth) { | 478 | void OTDriver::changeAuthentication(bool _auth) { |
477 | struct hci_dev_req dr; | 479 | struct hci_dev_req dr; |
478 | 480 | ||
479 | if( ! open() ) { | 481 | if( ! open() ) { |
480 | return; | 482 | return; |
481 | } | 483 | } |
482 | 484 | ||
483 | dr.dev_id = devId(); | 485 | dr.dev_id = devId(); |
484 | dr.dev_opt = _auth?AUTH_ENABLED:AUTH_DISABLED; | 486 | dr.dev_opt = _auth?AUTH_ENABLED:AUTH_DISABLED; |
485 | 487 | ||
486 | if (ioctl(fd(),HCISETAUTH,(unsigned long)&dr) < 0) { | 488 | if (ioctl(fd(),HCISETAUTH,(unsigned long)&dr) < 0) { |
487 | if( errno != EALREADY ) { | 489 | if( errno != EALREADY ) { |
488 | emit error( tr( "Can't change authentication on %1. %2 : %3" ). | 490 | emit error( tr( "Can't change authentication on %1. %2 : %3" ). |
489 | arg( devname() ). | 491 | arg( devname() ). |
490 | arg( errno ). | 492 | arg( errno ). |
491 | arg( strerror(errno) ) ); | 493 | arg( strerror(errno) ) ); |
492 | } | 494 | } |
493 | return; | 495 | return; |
494 | } | 496 | } |
495 | reinit(); | 497 | reinit(); |
496 | } | 498 | } |
497 | 499 | ||
498 | void OTDriver::changeEncryption(bool _encrypt) { | 500 | void OTDriver::changeEncryption(bool _encrypt) { |
499 | struct hci_dev_req dr; | 501 | struct hci_dev_req dr; |
500 | 502 | ||
501 | if( ! open() ) { | 503 | if( ! open() ) { |
502 | return; | 504 | return; |
503 | } | 505 | } |
504 | 506 | ||
505 | dr.dev_id = devId(); | 507 | dr.dev_id = devId(); |
506 | dr.dev_opt = _encrypt?ENCRYPT_P2P:ENCRYPT_DISABLED; | 508 | dr.dev_opt = _encrypt?ENCRYPT_P2P:ENCRYPT_DISABLED; |
507 | 509 | ||
508 | if (ioctl(fd(),HCISETENCRYPT,(unsigned long)&dr) < 0) { | 510 | if (ioctl(fd(),HCISETENCRYPT,(unsigned long)&dr) < 0) { |
509 | if( errno != EALREADY ) { | 511 | if( errno != EALREADY ) { |
510 | emit error( tr( "Can't change encryption on %1. %2 : %3" ). | 512 | emit error( tr( "Can't change encryption on %1. %2 : %3" ). |
511 | arg( devname() ). | 513 | arg( devname() ). |
512 | arg( errno ). | 514 | arg( errno ). |
513 | arg( strerror(errno) ) ); | 515 | arg( strerror(errno) ) ); |
514 | } | 516 | } |
515 | return; | 517 | return; |
516 | } | 518 | } |
517 | 519 | ||
518 | reinit(); | 520 | reinit(); |
519 | } | 521 | } |
520 | 522 | ||
521 | void OTDriver::changeClass ( unsigned char service, | 523 | void OTDriver::changeClass ( unsigned char service, |
522 | unsigned char major, | 524 | unsigned char major, |
523 | unsigned char minor ) { | 525 | unsigned char minor ) { |
524 | unsigned long cod = 0; | 526 | unsigned long cod = 0; |
525 | cod = (service << 16) | | 527 | cod = (service << 16) | |
526 | (major << 8) | | 528 | (major << 8) | |
527 | (minor ) ; | 529 | (minor ) ; |
528 | 530 | ||
529 | if( ! open() ) { | 531 | if( ! open() ) { |
530 | return; | 532 | return; |
531 | } | 533 | } |
532 | 534 | ||
533 | if ( hci_write_class_of_dev(fd(),cod,1000) < 0 ) { | 535 | if ( hci_write_class_of_dev(fd(),cod,1000) < 0 ) { |
534 | emit error( tr( "Can't change class informations for %1. %2 : %3" ). | 536 | emit error( tr( "Can't change class informations for %1. %2 : %3" ). |
535 | arg( devname() ). | 537 | arg( devname() ). |
536 | arg( errno ). | 538 | arg( errno ). |
537 | arg( strerror(errno) ) ); | 539 | arg( strerror(errno) ) ); |
538 | return; | 540 | return; |
539 | } | 541 | } |
540 | } | 542 | } |
541 | 543 | ||
542 | void OTDriver::getClass( QString & service, | 544 | void OTDriver::getClass( QString & service, |
543 | QString & device ) { | 545 | QString & device ) { |
544 | unsigned char cls[3]; | 546 | unsigned char cls[3]; |
545 | 547 | ||
546 | if( ! open() ) { | 548 | if( ! open() ) { |
547 | return; | 549 | return; |
548 | } | 550 | } |
549 | 551 | ||
550 | if ( hci_read_class_of_dev(fd(),cls,1000) < 0 ) { | 552 | if ( hci_read_class_of_dev(fd(),cls,1000) < 0 ) { |
551 | emit error( tr( "Can't read class information for %1. %2 : %3" ). | 553 | emit error( tr( "Can't read class information for %1. %2 : %3" ). |
552 | arg( devname() ). | 554 | arg( devname() ). |
553 | arg( errno ). | 555 | arg( errno ). |
554 | arg( strerror(errno) ) ); | 556 | arg( strerror(errno) ) ); |
555 | return; | 557 | return; |
556 | } | 558 | } |
557 | 559 | ||
558 | if( cls[2] ) { | 560 | if( cls[2] ) { |
559 | int first = 1; | 561 | int first = 1; |
560 | for ( unsigned int s = 0; s < sizeof(*services); s++) { | 562 | for ( unsigned int s = 0; s < sizeof(*services); s++) { |
561 | if (cls[2] & (1 << s)) { | 563 | if (cls[2] & (1 << s)) { |
562 | if( !first ) | 564 | if( !first ) |
563 | service += ", "; | 565 | service += ", "; |
564 | service += services[s]; | 566 | service += services[s]; |
565 | first = 0; | 567 | first = 0; |
566 | } | 568 | } |
567 | } | 569 | } |
568 | } else { | 570 | } else { |
569 | service = "unspecified"; | 571 | service = "unspecified"; |
570 | } | 572 | } |
571 | 573 | ||
572 | MainClassMap_t * MCM = MainClasses; | 574 | MainClassMap_t * MCM = MainClasses; |
573 | int major = cls[1] & 0x1f; | 575 | int major = cls[1] & 0x1f; |
574 | int minor = cls[0] >> 2; | 576 | int minor = cls[0] >> 2; |
575 | 577 | ||
576 | if( (unsigned)(cls[1] & 0x1f) > sizeof(*major_devices)) { | 578 | if( (unsigned)(cls[1] & 0x1f) > sizeof(*major_devices)) { |
577 | device = tr("Invalid Device Class"); | 579 | device = tr("Invalid Device Class"); |
578 | return; | 580 | return; |
579 | } | 581 | } |
580 | 582 | ||
581 | device = major_devices[cls[1] & 0x1f]; | 583 | device = major_devices[cls[1] & 0x1f]; |
582 | 584 | ||
583 | while( MCM->Major != -1 ) { | 585 | while( MCM->Major != -1 ) { |
584 | if( major == MCM->Major ) { | 586 | if( major == MCM->Major ) { |
585 | // this class | 587 | // this class |
586 | ClassMap_t * CM = MCM->Map; | 588 | ClassMap_t * CM = MCM->Map; |
587 | if( MCM->Map ) { | 589 | if( MCM->Map ) { |
588 | while( CM->Minor != -1 ) { | 590 | while( CM->Minor != -1 ) { |
589 | if( minor == CM->Minor ) { | 591 | if( minor == CM->Minor ) { |
590 | break; | 592 | break; |
591 | } | 593 | } |
592 | CM ++; | 594 | CM ++; |
593 | } | 595 | } |
594 | device = CM->Description; | 596 | device = CM->Description; |
595 | } else { | 597 | } else { |
596 | // special case | 598 | // special case |
597 | if( major == 3 ) { | 599 | if( major == 3 ) { |
598 | /* lan access */ | 600 | /* lan access */ |
599 | if( minor == 0 ) { | 601 | if( minor == 0 ) { |
600 | device = "Uncategorized"; | 602 | device = "Uncategorized"; |
601 | } else { | 603 | } else { |
602 | switch( minor / 8 ) { | 604 | switch( minor / 8 ) { |
603 | case 0: | 605 | case 0: |
604 | device = "Fully available"; | 606 | device = "Fully available"; |
605 | break; | 607 | break; |
606 | case 1: | 608 | case 1: |
607 | device = "1-17% utilized"; | 609 | device = "1-17% utilized"; |
608 | break; | 610 | break; |
609 | case 2: | 611 | case 2: |
610 | device = "17-33% utilized"; | 612 | device = "17-33% utilized"; |
611 | break; | 613 | break; |
612 | case 3: | 614 | case 3: |
613 | device = "33-50% utilized"; | 615 | device = "33-50% utilized"; |
614 | break; | 616 | break; |
615 | case 4: | 617 | case 4: |
616 | device = "50-67% utilized"; | 618 | device = "50-67% utilized"; |
617 | break; | 619 | break; |
618 | case 5: | 620 | case 5: |
619 | device = "67-83% utilized"; | 621 | device = "67-83% utilized"; |
620 | break; | 622 | break; |
621 | case 6: | 623 | case 6: |
622 | device = "83-99% utilized"; | 624 | device = "83-99% utilized"; |
623 | break; | 625 | break; |
624 | case 7: | 626 | case 7: |
625 | device = "No service available"; | 627 | device = "No service available"; |
626 | break; | 628 | break; |
627 | } | 629 | } |
628 | } | 630 | } |
629 | } else if( major == 6 ) { /* imaging */ | 631 | } else if( major == 6 ) { /* imaging */ |
630 | if (minor & 4) | 632 | if (minor & 4) |
631 | device = "Display"; | 633 | device = "Display"; |
632 | if (minor & 8) | 634 | if (minor & 8) |
633 | device = "Camera"; | 635 | device = "Camera"; |
634 | if (minor & 16) | 636 | if (minor & 16) |
635 | device = "Scanner"; | 637 | device = "Scanner"; |
636 | if (minor & 32) | 638 | if (minor & 32) |
637 | device = "Printer"; | 639 | device = "Printer"; |
638 | } | 640 | } |
639 | } | 641 | } |
640 | break; | 642 | break; |
641 | } | 643 | } |
642 | MCM ++; | 644 | MCM ++; |
643 | } | 645 | } |
644 | 646 | ||
645 | if( MCM->Major == -1 ) { | 647 | if( MCM->Major == -1 ) { |
646 | device = "Unknown (reserved) minor device class"; | 648 | device = "Unknown (reserved) minor device class"; |
647 | } | 649 | } |
648 | } | 650 | } |
649 | 651 | ||
650 | QString OTDriver::strType() { | 652 | QString OTDriver::strType() { |
651 | return QString( hci_dtypetostr(Type) ); | 653 | return QString( hci_dtypetostr(Type) ); |
652 | } | 654 | } |
653 | 655 | ||
654 | void OTDriver::setFeatures( unsigned char * _f) { | 656 | void OTDriver::setFeatures( unsigned char * _f) { |
655 | Features = lmp_featurestostr(_f, NULL, 255); | 657 | Features = lmp_featurestostr(_f, NULL, 255); |
656 | } | 658 | } |
657 | 659 | ||
658 | void OTDriver::setManufacturer(int compid) { | 660 | void OTDriver::setManufacturer(int compid) { |
659 | Manufacturer = bt_compidtostr(compid); | 661 | Manufacturer = bt_compidtostr(compid); |
660 | } | 662 | } |
661 | 663 | ||
662 | OTHCISocket * OTDriver::openSocket( void ) { | 664 | OTHCISocket * OTDriver::openSocket( void ) { |
663 | if( ! Socket ) { | 665 | if( ! Socket ) { |
664 | odebug << "Open HCI socket to " << devname() << oendl; | 666 | odebug << "Open HCI socket to " << devname() << oendl; |
665 | Socket = new OTHCISocket( this ); | 667 | Socket = new OTHCISocket( this ); |
666 | } | 668 | } |
667 | return Socket; | 669 | return Socket; |
668 | } | 670 | } |
669 | 671 | ||
670 | void OTDriver::closeSocket( void ) { | 672 | void OTDriver::closeSocket( void ) { |
671 | if( Socket ) { | 673 | if( Socket ) { |
672 | odebug << "Close HCI socket to " << devname() << oendl; | 674 | odebug << "Close HCI socket to " << devname() << oendl; |
673 | delete Socket; | 675 | delete Socket; |
674 | Socket = 0; | 676 | Socket = 0; |
675 | } | 677 | } |
676 | } | 678 | } |
677 | 679 | ||
678 | QString OTDriver::getPeerName( const OTDeviceAddress & PAddr ) { | 680 | QString OTDriver::getPeerName( const OTDeviceAddress & PAddr ) { |
679 | QString S; | 681 | QString S; |
680 | char name[100 ]; | 682 | char name[100 ]; |
681 | 683 | ||
682 | if( ! open() ) { | 684 | if( ! open() ) { |
683 | return QString("N/A"); | 685 | return QString("N/A"); |
684 | } | 686 | } |
685 | 687 | ||
686 | if( hci_read_remote_name( fd(), | 688 | if( hci_read_remote_name( fd(), |
687 | &(PAddr.getBDAddr()), | 689 | &(PAddr.getBDAddr()), |
688 | sizeof(name), | 690 | sizeof(name), |
689 | name, | 691 | name, |
690 | 100000 ) < 0 ) { | 692 | 100000 ) < 0 ) { |
691 | return QString( "N/A" ); | 693 | return QString( "N/A" ); |
692 | } | 694 | } |
693 | 695 | ||
694 | return QString( name ); | 696 | return QString( name ); |
695 | } | 697 | } |
696 | 698 | ||
697 | long OTDriver::getLinkQuality( const OTDeviceAddress & Addr ) { | 699 | long OTDriver::getLinkQuality( const OTDeviceAddress & Addr ) { |
698 | struct hci_conn_info_req *cr; | 700 | struct hci_conn_info_req *cr; |
699 | struct hci_request rq; | 701 | struct hci_request rq; |
700 | read_rssi_rp rp; | 702 | read_rssi_rp rp; |
701 | uint16_t handle; | 703 | uint16_t handle; |
702 | 704 | ||
703 | if( ! open() ) { | 705 | if( ! open() ) { |
704 | return 0; | 706 | return 0; |
705 | } | 707 | } |
706 | 708 | ||
707 | cr = (struct hci_conn_info_req *)malloc( | 709 | cr = (struct hci_conn_info_req *)malloc( |
708 | sizeof(*cr) + sizeof(struct hci_conn_info)); | 710 | sizeof(*cr) + sizeof(struct hci_conn_info)); |
709 | if (!cr) | 711 | if (!cr) |
710 | return 0; | 712 | return 0; |
711 | 713 | ||
712 | bacpy( &(cr->bdaddr), &(Addr.getBDAddr()) ); | 714 | bacpy( &(cr->bdaddr), &(Addr.getBDAddr()) ); |
713 | cr->type = ACL_LINK; | 715 | cr->type = ACL_LINK; |
714 | 716 | ||
715 | if (ioctl( fd(), HCIGETCONNINFO, (unsigned long) cr) < 0) { | 717 | if (ioctl( fd(), HCIGETCONNINFO, (unsigned long) cr) < 0) { |
716 | odebug << "Get NetworkSetup info failed" << oendl; | 718 | odebug << "Get NetworkSetup info failed" << oendl; |
717 | free(cr); | 719 | free(cr); |
718 | return 0; | 720 | return 0; |
719 | } | 721 | } |
720 | 722 | ||
721 | handle = htobs(cr->conn_info->handle); | 723 | handle = htobs(cr->conn_info->handle); |
722 | 724 | ||
723 | free(cr); | 725 | free(cr); |
724 | 726 | ||
725 | memset(&rq, 0, sizeof(rq)); | 727 | memset(&rq, 0, sizeof(rq)); |
726 | rq.ogf = OGF_STATUS_PARAM; | 728 | rq.ogf = OGF_STATUS_PARAM; |
727 | rq.ocf = OCF_READ_RSSI; | 729 | rq.ocf = OCF_READ_RSSI; |
728 | rq.cparam = &handle; | 730 | rq.cparam = &handle; |
729 | rq.clen = 2; | 731 | rq.clen = 2; |
730 | rq.rparam = &rp; | 732 | rq.rparam = &rp; |
731 | rq.rlen = GET_LINK_QUALITY_RP_SIZE; | 733 | rq.rlen = GET_LINK_QUALITY_RP_SIZE; |
732 | 734 | ||
733 | if (hci_send_req( fd(), &rq, 100) < 0) { | 735 | if (hci_send_req( fd(), &rq, 100) < 0) { |
734 | odebug << "Get NetworkSetup info failed" << oendl; | 736 | odebug << "Get NetworkSetup info failed" << oendl; |
735 | return 0; | 737 | return 0; |
736 | } | 738 | } |
737 | 739 | ||
738 | if( rp.status ) { | 740 | if( rp.status ) { |
739 | odebug << QString().sprintf("HCI get_link_quality cmd failed (0x%2.2X)", rp.status) << oendl; | 741 | odebug << QString().sprintf("HCI get_link_quality cmd failed (0x%2.2X)", rp.status) << oendl; |
740 | return 0; | 742 | return 0; |
741 | } | 743 | } |
742 | 744 | ||
743 | return rp.rssi+50; | 745 | return rp.rssi+50; |
744 | } | 746 | } |