Diffstat (limited to 'noncore/settings/networksettings2/opietooth2/OTPeer.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/networksettings2/opietooth2/OTPeer.cpp | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/noncore/settings/networksettings2/opietooth2/OTPeer.cpp b/noncore/settings/networksettings2/opietooth2/OTPeer.cpp index 0d7e943..2272f04 100644 --- a/noncore/settings/networksettings2/opietooth2/OTPeer.cpp +++ b/noncore/settings/networksettings2/opietooth2/OTPeer.cpp | |||
@@ -38,62 +38,62 @@ OTPeer::OTPeer( QTextStream & TS, OTGateway * _OT ) { | |||
38 | OT = _OT; | 38 | OT = _OT; |
39 | State = Peer_Unknown; | 39 | State = Peer_Unknown; |
40 | ConnectedTo = 0; | 40 | ConnectedTo = 0; |
41 | 41 | ||
42 | load( TS ); | 42 | load( TS ); |
43 | } | 43 | } |
44 | 44 | ||
45 | OTPeer::~OTPeer( ) { | 45 | OTPeer::~OTPeer( ) { |
46 | 46 | ||
47 | } | 47 | } |
48 | 48 | ||
49 | void OTPeer::updateServices( void ) { | 49 | void OTPeer::updateServices( void ) { |
50 | sdp_session_t *session; | 50 | sdp_session_t *session; |
51 | 51 | ||
52 | serviceList.clear(); | 52 | serviceList.clear(); |
53 | 53 | ||
54 | owarn << "Get services from " << Addr.toString() << oendl; | 54 | odebug << "Get services from " << Addr.toString() << oendl; |
55 | 55 | ||
56 | session = sdp_connect( &(OTDeviceAddress::any.getBDAddr()), | 56 | session = sdp_connect( &(OTDeviceAddress::any.getBDAddr()), |
57 | &(Addr.getBDAddr()), | 57 | &(Addr.getBDAddr()), |
58 | 0); | 58 | 0); |
59 | 59 | ||
60 | if (!session) { | 60 | if (!session) { |
61 | owarn << "sdp_connect(" | 61 | odebug << "sdp_connect(" |
62 | << Addr.toString() | 62 | << Addr.toString() |
63 | << ") failed" | 63 | << ") failed" |
64 | << oendl; | 64 | << oendl; |
65 | return; // error | 65 | return; // error |
66 | } | 66 | } |
67 | 67 | ||
68 | uint32_t range = 0x0000ffff; | 68 | uint32_t range = 0x0000ffff; |
69 | sdp_list_t* attrId = sdp_list_append(0, &range); | 69 | sdp_list_t* attrId = sdp_list_append(0, &range); |
70 | 70 | ||
71 | // search all public features | 71 | // search all public features |
72 | uuid_t grp; | 72 | uuid_t grp; |
73 | sdp_uuid16_create( &grp, PUBLIC_BROWSE_GROUP ); | 73 | sdp_uuid16_create( &grp, PUBLIC_BROWSE_GROUP ); |
74 | sdp_list_t * search = sdp_list_append(0, &grp ); | 74 | sdp_list_t * search = sdp_list_append(0, &grp ); |
75 | 75 | ||
76 | // get data from peer | 76 | // get data from peer |
77 | sdp_list_t* seq; | 77 | sdp_list_t* seq; |
78 | if (sdp_service_search_attr_req( session, | 78 | if (sdp_service_search_attr_req( session, |
79 | search, | 79 | search, |
80 | SDP_ATTR_REQ_RANGE, | 80 | SDP_ATTR_REQ_RANGE, |
81 | attrId, | 81 | attrId, |
82 | &seq ) ) { | 82 | &seq ) ) { |
83 | owarn << "Service Search failed" << oendl; | 83 | odebug << "Service Search failed" << oendl; |
84 | sdp_close(session); | 84 | sdp_close(session); |
85 | return; | 85 | return; |
86 | } | 86 | } |
87 | 87 | ||
88 | sdp_list_free(attrId, 0); | 88 | sdp_list_free(attrId, 0); |
89 | sdp_list_free(search, 0); | 89 | sdp_list_free(search, 0); |
90 | 90 | ||
91 | // process result | 91 | // process result |
92 | sdp_list_t* next = NULL; | 92 | sdp_list_t* next = NULL; |
93 | 93 | ||
94 | for (; seq; seq = next) { | 94 | for (; seq; seq = next) { |
95 | sdp_record_t *rec = (sdp_record_t *) seq->data; | 95 | sdp_record_t *rec = (sdp_record_t *) seq->data; |
96 | 96 | ||
97 | sdp_list_t* attrlist = rec->attrlist; | 97 | sdp_list_t* attrlist = rec->attrlist; |
98 | AttributeVector alist; | 98 | AttributeVector alist; |
99 | OTSDPService * service; | 99 | OTSDPService * service; |
@@ -164,33 +164,33 @@ void OTPeer::load( QTextStream & TS ) { | |||
164 | setDeviceClass( S.mid( 6 ).toLong() ); | 164 | setDeviceClass( S.mid( 6 ).toLong() ); |
165 | } | 165 | } |
166 | 166 | ||
167 | #define MAGICNR -99999 | 167 | #define MAGICNR -99999 |
168 | #define POLLDELAY 1000 | 168 | #define POLLDELAY 1000 |
169 | #define PREMAGICNR (MAGICNR+POLLDELAY) | 169 | #define PREMAGICNR (MAGICNR+POLLDELAY) |
170 | 170 | ||
171 | void OTPeer::findOutState( int timeoutInSec, bool Force ) { | 171 | void OTPeer::findOutState( int timeoutInSec, bool Force ) { |
172 | ProbeFD = -1; | 172 | ProbeFD = -1; |
173 | if( Force && ConnectedTo == 0 ) { | 173 | if( Force && ConnectedTo == 0 ) { |
174 | State = OTPeer::Peer_Unknown; | 174 | State = OTPeer::Peer_Unknown; |
175 | } // else keep state or is connected to us | 175 | } // else keep state or is connected to us |
176 | 176 | ||
177 | if( State == OTPeer::Peer_Unknown ) { | 177 | if( State == OTPeer::Peer_Unknown ) { |
178 | ProbePhase = 0; | 178 | ProbePhase = 0; |
179 | ProbeTimeout = timeoutInSec*1000; | 179 | ProbeTimeout = timeoutInSec*1000; |
180 | owarn << "Ping " << address().toString() << oendl; | 180 | odebug << "Ping " << address().toString() << oendl; |
181 | startTimer( POLLDELAY ); | 181 | startTimer( POLLDELAY ); |
182 | } else { | 182 | } else { |
183 | ProbeTimeout = 0; | 183 | ProbeTimeout = 0; |
184 | startTimer( 0 ); | 184 | startTimer( 0 ); |
185 | } | 185 | } |
186 | } | 186 | } |
187 | 187 | ||
188 | #define PINGSIZE 20 | 188 | #define PINGSIZE 20 |
189 | void OTPeer::timerEvent( QTimerEvent * ev ) { | 189 | void OTPeer::timerEvent( QTimerEvent * ev ) { |
190 | 190 | ||
191 | ProbeTimeout -= POLLDELAY; | 191 | ProbeTimeout -= POLLDELAY; |
192 | 192 | ||
193 | if( State == OTPeer::Peer_Unknown ) { | 193 | if( State == OTPeer::Peer_Unknown ) { |
194 | switch( ProbePhase ) { | 194 | switch( ProbePhase ) { |
195 | case 0 : // connect nonblock | 195 | case 0 : // connect nonblock |
196 | { struct sockaddr_l2 addr; | 196 | { struct sockaddr_l2 addr; |
@@ -222,128 +222,128 @@ void OTPeer::timerEvent( QTimerEvent * ev ) { | |||
222 | if( errno != EAGAIN && errno != EINPROGRESS ) { | 222 | if( errno != EAGAIN && errno != EINPROGRESS ) { |
223 | ProbeTimeout = 0; | 223 | ProbeTimeout = 0; |
224 | break; | 224 | break; |
225 | } // wait for connect to fail or succeed | 225 | } // wait for connect to fail or succeed |
226 | } | 226 | } |
227 | } | 227 | } |
228 | ProbePhase = 1; // wait for connect | 228 | ProbePhase = 1; // wait for connect |
229 | break; | 229 | break; |
230 | case 1 : | 230 | case 1 : |
231 | { struct pollfd pf[1]; | 231 | { struct pollfd pf[1]; |
232 | char buf[L2CAP_CMD_HDR_SIZE + PINGSIZE + 20]; | 232 | char buf[L2CAP_CMD_HDR_SIZE + PINGSIZE + 20]; |
233 | int n; | 233 | int n; |
234 | 234 | ||
235 | pf[0].fd = ProbeFD; | 235 | pf[0].fd = ProbeFD; |
236 | pf[0].events = POLLOUT; | 236 | pf[0].events = POLLOUT; |
237 | if( (n = ::poll(pf, 1, 0)) < 0 ) { | 237 | if( (n = ::poll(pf, 1, 0)) < 0 ) { |
238 | owarn << address().toString() | 238 | odebug << address().toString() |
239 | << " : errno " | 239 | << " : errno " |
240 | << errno | 240 | << errno |
241 | << " " | 241 | << " " |
242 | << strerror(errno)<<oendl; | 242 | << strerror(errno)<<oendl; |
243 | ProbeTimeout = 0; | 243 | ProbeTimeout = 0; |
244 | break; | 244 | break; |
245 | } | 245 | } |
246 | 246 | ||
247 | if( ! n ) { | 247 | if( ! n ) { |
248 | // not ready -> try again | 248 | // not ready -> try again |
249 | break; | 249 | break; |
250 | } | 250 | } |
251 | 251 | ||
252 | // send ping | 252 | // send ping |
253 | for( unsigned int i = L2CAP_CMD_HDR_SIZE; i < sizeof(buf); i++) | 253 | for( unsigned int i = L2CAP_CMD_HDR_SIZE; i < sizeof(buf); i++) |
254 | buf[i] = (i % 40) + 'A'; | 254 | buf[i] = (i % 40) + 'A'; |
255 | 255 | ||
256 | l2cap_cmd_hdr *cmd = (l2cap_cmd_hdr *) buf; | 256 | l2cap_cmd_hdr *cmd = (l2cap_cmd_hdr *) buf; |
257 | 257 | ||
258 | /* Build command header */ | 258 | /* Build command header */ |
259 | cmd->code = L2CAP_ECHO_REQ; | 259 | cmd->code = L2CAP_ECHO_REQ; |
260 | cmd->ident = *(char *)this; // get some byte | 260 | cmd->ident = *(char *)this; // get some byte |
261 | cmd->len = PINGSIZE; | 261 | cmd->len = PINGSIZE; |
262 | 262 | ||
263 | /* Send Echo Request */ | 263 | /* Send Echo Request */ |
264 | if( ::send(ProbeFD, buf, PINGSIZE + L2CAP_CMD_HDR_SIZE, 0) <= 0) { | 264 | if( ::send(ProbeFD, buf, PINGSIZE + L2CAP_CMD_HDR_SIZE, 0) <= 0) { |
265 | if( errno == EACCES ) { | 265 | if( errno == EACCES ) { |
266 | // permission denied means that we could not | 266 | // permission denied means that we could not |
267 | // connect because the device does not allow us | 267 | // connect because the device does not allow us |
268 | // but it is UP | 268 | // but it is UP |
269 | owarn << address().toString() | 269 | odebug << address().toString() |
270 | << " good send error " | 270 | << " good send error " |
271 | << errno | 271 | << errno |
272 | << " " | 272 | << " " |
273 | << strerror( errno) | 273 | << strerror( errno) |
274 | << oendl; | 274 | << oendl; |
275 | State = OTPeer::Peer_Up; | 275 | State = OTPeer::Peer_Up; |
276 | ProbeTimeout = 0; | 276 | ProbeTimeout = 0; |
277 | break; | 277 | break; |
278 | } else if( errno != EBUSY ) { | 278 | } else if( errno != EBUSY ) { |
279 | owarn << address().toString() | 279 | odebug << address().toString() |
280 | << " : errno " | 280 | << " : errno " |
281 | << errno | 281 | << errno |
282 | << " " | 282 | << " " |
283 | << strerror(errno) | 283 | << strerror(errno) |
284 | << oendl; | 284 | << oendl; |
285 | ProbeTimeout = 0; | 285 | ProbeTimeout = 0; |
286 | break; | 286 | break; |
287 | } // else want some more | 287 | } // else want some more |
288 | } | 288 | } |
289 | 289 | ||
290 | ProbePhase = 2; // wait for ping reply | 290 | ProbePhase = 2; // wait for ping reply |
291 | } | 291 | } |
292 | break; | 292 | break; |
293 | case 2 : // wait for reply | 293 | case 2 : // wait for reply |
294 | { struct pollfd pf[1]; | 294 | { struct pollfd pf[1]; |
295 | char buf[L2CAP_CMD_HDR_SIZE + PINGSIZE + 20]; | 295 | char buf[L2CAP_CMD_HDR_SIZE + PINGSIZE + 20]; |
296 | l2cap_cmd_hdr *cmd = (l2cap_cmd_hdr *) buf; | 296 | l2cap_cmd_hdr *cmd = (l2cap_cmd_hdr *) buf; |
297 | int n; | 297 | int n; |
298 | 298 | ||
299 | pf[0].fd = ProbeFD; | 299 | pf[0].fd = ProbeFD; |
300 | pf[0].events = POLLIN; | 300 | pf[0].events = POLLIN; |
301 | if( (n = ::poll(pf, 1, 0)) < 0 ) { | 301 | if( (n = ::poll(pf, 1, 0)) < 0 ) { |
302 | owarn << address().toString() | 302 | odebug << address().toString() |
303 | << " : errno " | 303 | << " : errno " |
304 | << errno | 304 | << errno |
305 | << " " | 305 | << " " |
306 | << strerror(errno) | 306 | << strerror(errno) |
307 | <<oendl; | 307 | <<oendl; |
308 | ProbeTimeout = 0; | 308 | ProbeTimeout = 0; |
309 | break; | 309 | break; |
310 | } | 310 | } |
311 | 311 | ||
312 | if( ! n ) { | 312 | if( ! n ) { |
313 | // not ready -> try again | 313 | // not ready -> try again |
314 | break; | 314 | break; |
315 | } | 315 | } |
316 | 316 | ||
317 | if( (n = ::recv( ProbeFD, buf, sizeof(buf), 0)) < 0) { | 317 | if( (n = ::recv( ProbeFD, buf, sizeof(buf), 0)) < 0) { |
318 | owarn << address().toString() | 318 | odebug << address().toString() |
319 | << "errno " | 319 | << "errno " |
320 | << errno | 320 | << errno |
321 | << " " | 321 | << " " |
322 | << strerror(errno) | 322 | << strerror(errno) |
323 | << oendl; | 323 | << oendl; |
324 | ProbeTimeout = 0; | 324 | ProbeTimeout = 0; |
325 | break; | 325 | break; |
326 | } | 326 | } |
327 | 327 | ||
328 | /* Check for our id */ | 328 | /* Check for our id */ |
329 | if( cmd->ident != *(char *)this ) | 329 | if( cmd->ident != *(char *)this ) |
330 | // not our reply | 330 | // not our reply |
331 | break; | 331 | break; |
332 | 332 | ||
333 | owarn << "reply from " | 333 | odebug << "reply from " |
334 | << address().toString() | 334 | << address().toString() |
335 | << oendl; | 335 | << oendl; |
336 | // whatever reply we get is a valid reply | 336 | // whatever reply we get is a valid reply |
337 | State = OTPeer::Peer_Up; | 337 | State = OTPeer::Peer_Up; |
338 | ProbeTimeout = 0; | 338 | ProbeTimeout = 0; |
339 | } | 339 | } |
340 | break; | 340 | break; |
341 | } | 341 | } |
342 | 342 | ||
343 | if( State != OTPeer::Peer_Unknown ) { | 343 | if( State != OTPeer::Peer_Unknown ) { |
344 | ProbeTimeout = 0; | 344 | ProbeTimeout = 0; |
345 | } | 345 | } |
346 | } | 346 | } |
347 | 347 | ||
348 | if( ProbeTimeout <= 0 ) { | 348 | if( ProbeTimeout <= 0 ) { |
349 | // regular timeout | 349 | // regular timeout |