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,400 +1,402 @@ | |||
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) ) ); |