- Timestamp:
- Jul 24, 2009, 8:53:41 PM (15 years ago)
- Location:
- source/ariba/utility/bootstrap/modules/bluetoothsdp
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
source/ariba/utility/bootstrap/modules/bluetoothsdp
- Property svn:mergeinfo changed (with no actual effect on merging)
-
source/ariba/utility/bootstrap/modules/bluetoothsdp/BluetoothSdp.cpp
r4970 r5316 41 41 #ifdef HAVE_BLUETOOTH_BLUETOOTH_H 42 42 43 // Attribute descriptors for SDP44 // base was chosen randomly45 #define SDP_SPOVNET_BASE 0x400046 #define SDP_ATTR_SPOVNET_NAME 0x0000 + SDP_SPOVNET_BASE47 #define SDP_ATTR_SPOVNET_INFO1 0x0001 + SDP_SPOVNET_BASE48 #define SDP_ATTR_SPOVNET_INFO2 0x0002 + SDP_SPOVNET_BASE49 #define SDP_ATTR_SPOVNET_INFO3 0x0003 + SDP_SPOVNET_BASE50 51 // The SpoVNet unique identifier, this should be the same for all SpoVNet implementations52 const uint8_t svc_uuid_int[] = {0x59, 0x29, 0x24, 0x34, 0x69, 0x42, 0x11, 0xde, 0x94,53 0x3e, 0x00, 0x21, 0x5d, 0xb4, 0xd8, 0x54};54 55 const char *service_name = "SpoVNet";56 const char *svc_dsc = "Spontaneous Virtual Network";57 const char *service_prov = "ITM Uni Karlsruhe";43 // Attribute descriptors for SDP 44 // base was chosen randomly 45 #define SDP_SPOVNET_BASE 0x4000 46 #define SDP_ATTR_SPOVNET_NAME 0x0000 + SDP_SPOVNET_BASE 47 #define SDP_ATTR_SPOVNET_INFO1 0x0001 + SDP_SPOVNET_BASE 48 #define SDP_ATTR_SPOVNET_INFO2 0x0002 + SDP_SPOVNET_BASE 49 #define SDP_ATTR_SPOVNET_INFO3 0x0003 + SDP_SPOVNET_BASE 50 51 // The SpoVNet unique identifier, this should be the same for all SpoVNet implementations 52 const uint8_t svc_uuid_int[] = {0x59, 0x29, 0x24, 0x34, 0x69, 0x42, 0x11, 0xde, 0x94, 53 0x3e, 0x00, 0x21, 0x5d, 0xb4, 0xd8, 0x54}; 54 55 const char *service_name = "SpoVNet"; 56 const char *svc_dsc = "www.ariba-underlay.org"; 57 const char *service_prov = "ITM Uni Karlsruhe"; 58 58 59 59 #endif // HAVE_BLUETOOTH_BLUETOOTH_H … … 66 66 BluetoothSdp::BluetoothSdp(BootstrapInformationCallback* _callback) : 67 67 BootstrapModule(_callback), scan_timer_(io_service_) { 68 srand( time(NULL) ); 68 69 #ifdef HAVE_BLUETOOTH_BLUETOOTH_H 69 70 … … 88 89 bool BluetoothSdp::isFunctional() { 89 90 #ifdef HAVE_BLUETOOTH_BLUETOOTH_H 90 return true; // Not tested yet :)91 return true; 91 92 #else 92 93 return false; … … 118 119 t_.join(); 119 120 121 if(sdp_session_ != NULL) 122 sdp_close(sdp_session_); 123 120 124 #endif // HAVE_BLUETOOTH_BLUETOOTH_H 121 125 } … … 130 134 */ 131 135 132 logging_ info("Registering SDP service");136 logging_debug("registering SDP service"); 133 137 134 138 uint8_t rfcomm_channel = channel_; … … 142 146 sdp_session_ = 0; 143 147 144 bdaddr_t bdaddr_any = (bdaddr_t) { {0, 0, 0, 0, 0, 0}};145 bdaddr_t bdaddr_local = (bdaddr_t) { {0, 0, 0, 0xff, 0xff, 0xff}};146 147 148 // prepare the info attribute buffers 148 149 //string namebuf, info1buf, info2buf, info3buf; … … 155 156 156 157 if((namelen > 256) || (info1len > 256) || (info2len > 256) || (info3len > 256)) { 157 logging_error(" String Argument too long, max size is 256!");158 logging_error("string argument too long, max size is 256!"); 158 159 return; 159 160 } 160 161 // we need to save the string len for sdp; do we?162 /*163 namebuf = (char)namelen;164 namebuf.append(name);165 info1buf = (char)info1len;166 info1buf.append(info1);167 info2buf = (char)info2len;168 info2buf.append(info2);169 info3buf = (char)info3len;170 info3buf.append(info3);171 */172 161 173 162 // set the general service ID … … 222 211 info3.data()); 223 212 224 // connect to the local SDP server, register the service record, 225 // and disconnect 226 sdp_session_ = sdp_connect(&bdaddr_any, &bdaddr_local, SDP_RETRY_IF_BUSY); 227 228 if (sdp_session_ == 0) { 229 logging_error( "Something is wrong with your SDP server, nothing registered" ); 213 // connect to the local SDP server, register the service record 214 if( sdp_session_ == NULL ){ 215 sdp_session_ = sdp_connect(BDADDR_ANY, BDADDR_LOCAL, SDP_RETRY_IF_BUSY); 216 } 217 218 if (sdp_session_ == NULL) { 219 logging_error( "something is wrong with your SDP server, nothing registered" ); 230 220 } else { 231 sdp_record_register(sdp_session_, &record, 0); 221 int ret = sdp_record_register(sdp_session_, &record, 0); 222 223 if(ret < 0){ 224 logging_error("failed registering sdp record"); 225 }else{ 226 logging_debug("sdp record registered using session " << sdp_session_); 227 } 232 228 } 233 229 … … 247 243 #ifdef HAVE_BLUETOOTH_BLUETOOTH_H 248 244 249 logging_ info("Unregistering SDP service");245 logging_debug("unregistering SDP service"); 250 246 sdp_close(sdp_session_); 251 247 … … 256 252 257 253 void BluetoothSdp::bt_scan() { 258 259 260 254 /* 261 255 * Scans for other bluetooth devices and starts a SDP search on them. 262 * Repeats 20 seconds after the end of the scan. 263 */ 264 265 logging_info("Scanning for peers"); 256 */ 257 258 logging_debug("scanning for peers"); 266 259 267 260 inquiry_info *ii = NULL; … … 276 269 sock = hci_open_dev(dev_id); 277 270 if (dev_id < 0 || sock < 0) { 278 logging_error("opening socket ");279 exit(1);271 logging_error("opening socket for device " << dev_id << " failed. can not scan for peers"); 272 return; 280 273 } 281 274 … … 287 280 num_rsp = hci_inquiry(dev_id, len, max_rsp, NULL, &ii, flags); 288 281 if (num_rsp < 0) 289 logging_error("hci_inquiry ");282 logging_error("hci_inquiry failed with " << num_rsp); 290 283 291 284 for (i = 0; i < num_rsp; i++) { 292 /*293 ba2str(&(ii + i)->bdaddr, addr);294 memset(name, 0, sizeof(name));295 if (hci_read_remote_name(sock, &(ii + i)->bdaddr, sizeof(name),296 name, 0) < 0)297 strcpy(name, "[unknown]");298 printf("%s %s\n", addr, name);299 */300 285 301 286 address = (ii + i)->bdaddr; 302 303 logging_info("Found peer " << ba2string(&address) << ", querying SDP.") 287 logging_debug("found peer " << ba2string(&address) << ", querying SDP.") 304 288 305 289 // TODO: sdp_search can be very slow, fork it! … … 310 294 close(sock); 311 295 312 logging_info("Next scan in 20 seconds"); 313 314 scan_timer_.expires_from_now(boost::posix_time::seconds(20)); 296 int nextscan = (rand() % 40) + 5; 297 logging_debug("Next sdp scan in " << nextscan << " seconds"); 298 299 scan_timer_.expires_from_now(boost::posix_time::seconds(nextscan)); 315 300 scan_timer_.async_wait(boost::bind(&BluetoothSdp::bt_scan, this)); 316 301 } … … 326 311 uuid_t svc_uuid; 327 312 sdp_list_t *response_list, *search_list, *attrid_list; 328 sdp_session_t *session = 0;313 sdp_session_t *session = NULL; 329 314 uint32_t range = 0x0000ffff; 330 315 uint8_t port = 0; 331 bdaddr_t any_addr = (bdaddr_t) { {0, 0, 0, 0, 0, 0}};332 316 333 317 // prepare the buffers for the attributes … … 335 319 336 320 // connect to the SDP server running on the remote machine 337 session = sdp_connect(&any_addr, &target, 0); 338 339 if (session == 0) { 340 logging_error("Failed to connect to SDP server at " << ba2string(&target) <<"."); 321 logging_debug("querying services from bt device " << ba2string(&target)); 322 session = sdp_connect(BDADDR_ANY, &target, 0); 323 324 if (session == NULL) { 325 logging_error("failed to connect to SDP server at " << ba2string(&target) <<"."); 341 326 return; 342 327 } … … 356 341 357 342 // go through each of the service records 358 for ( ; r; r = r->next) {343 for ( ; r != NULL; r = r->next) { 359 344 sdp_record_t *rec = (sdp_record_t*) r->data; 360 345 … … 368 353 369 354 sdp_get_string_attr(rec, SDP_ATTR_SPOVNET_NAME, (char*)&name, 256); 370 sdp_get_string_attr(rec, SDP_ATTR_SPOVNET_INFO1, (char*)& name, 256);371 sdp_get_string_attr(rec, SDP_ATTR_SPOVNET_INFO2, (char*)& name, 256);372 sdp_get_string_attr(rec, SDP_ATTR_SPOVNET_INFO3, (char*)& name, 256);355 sdp_get_string_attr(rec, SDP_ATTR_SPOVNET_INFO1, (char*)&info1, 256); 356 sdp_get_string_attr(rec, SDP_ATTR_SPOVNET_INFO2, (char*)&info2, 256); 357 sdp_get_string_attr(rec, SDP_ATTR_SPOVNET_INFO3, (char*)&info3, 256); 373 358 374 359 logging_info("Remote peer name is: " << name); … … 379 364 // Callback 380 365 callback->onBootstrapServiceFound(name, info1, info2, info3); 381 382 366 } 383 367 sdp_record_free(rec); 384 368 } 385 } 369 } else { 370 logging_error("sdp_service_search_attr_req failed with timeout"); 371 } 372 386 373 sdp_list_free(response_list, 0); 387 374 sdp_list_free(search_list, 0); 388 375 sdp_list_free(attrid_list, 0); 389 376 sdp_close(session); 390 391 377 } 392 378 … … 395 381 * Returns a string holding the bt adress in human readable form. 396 382 */ 397 char *str; 383 char addr[32] = { 0 }; 384 char str[32] = { 0 }; 398 385 ba2str(ba, str); 399 386 string result = str;
Note:
See TracChangeset
for help on using the changeset viewer.