An Overlay-based
Virtual Network Substrate
SpoVNet

Ignore:
Timestamp:
Jul 24, 2009, 8:53:41 PM (10 years ago)
Author:
Christoph Mayer
Message:

merge from bootstrap branch

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  
    4141#ifdef HAVE_BLUETOOTH_BLUETOOTH_H
    4242
    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 = "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";
    5858
    5959#endif // HAVE_BLUETOOTH_BLUETOOTH_H
     
    6666BluetoothSdp::BluetoothSdp(BootstrapInformationCallback* _callback) :
    6767        BootstrapModule(_callback), scan_timer_(io_service_) {
     68        srand( time(NULL) );
    6869#ifdef HAVE_BLUETOOTH_BLUETOOTH_H
    6970
     
    8889bool BluetoothSdp::isFunctional() {
    8990#ifdef HAVE_BLUETOOTH_BLUETOOTH_H
    90         return true; // Not tested yet :)
     91        return true;
    9192#else
    9293        return false;
     
    118119        t_.join();
    119120
     121        if(sdp_session_ != NULL)
     122                sdp_close(sdp_session_);
     123
    120124#endif // HAVE_BLUETOOTH_BLUETOOTH_H
    121125}
     
    130134         */
    131135
    132         logging_info("Registering SDP service");
     136        logging_debug("registering SDP service");
    133137
    134138        uint8_t rfcomm_channel = channel_;
     
    142146        sdp_session_ = 0;
    143147
    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 
    147148        // prepare the info attribute buffers
    148149        //string namebuf, info1buf, info2buf, info3buf;
     
    155156
    156157        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!");
    158159                return;
    159160        }
    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         */
    172161
    173162        // set the general service ID
     
    222211                        info3.data());
    223212
    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" );
    230220        } 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                }
    232228        }
    233229
     
    247243#ifdef HAVE_BLUETOOTH_BLUETOOTH_H
    248244
    249         logging_info("Unregistering SDP service");
     245        logging_debug("unregistering SDP service");
    250246        sdp_close(sdp_session_);
    251247
     
    256252
    257253void BluetoothSdp::bt_scan() {
    258 
    259 
    260254        /*
    261255         * 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");
    266259
    267260        inquiry_info *ii = NULL;
     
    276269        sock = hci_open_dev(dev_id);
    277270        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;
    280273        }
    281274
     
    287280        num_rsp = hci_inquiry(dev_id, len, max_rsp, NULL, &ii, flags);
    288281        if (num_rsp < 0)
    289                 logging_error("hci_inquiry");
     282                logging_error("hci_inquiry failed with " << num_rsp);
    290283
    291284        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                  */
    300285
    301286                address = (ii + i)->bdaddr;
    302 
    303                 logging_info("Found peer " << ba2string(&address) << ", querying SDP.")
     287                logging_debug("found peer " << ba2string(&address) << ", querying SDP.")
    304288
    305289                // TODO: sdp_search can be very slow, fork it!
     
    310294        close(sock);
    311295
    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));
    315300        scan_timer_.async_wait(boost::bind(&BluetoothSdp::bt_scan, this));
    316301}
     
    326311        uuid_t svc_uuid;
    327312        sdp_list_t *response_list, *search_list, *attrid_list;
    328         sdp_session_t *session = 0;
     313        sdp_session_t *session = NULL;
    329314        uint32_t range = 0x0000ffff;
    330315        uint8_t port = 0;
    331         bdaddr_t any_addr = (bdaddr_t) { {0, 0, 0, 0, 0, 0}};
    332316
    333317        // prepare the buffers for the attributes
     
    335319
    336320        // 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) <<".");
    341326                return;
    342327        }
     
    356341
    357342                // go through each of the service records
    358                 for (; r; r = r->next) {
     343                for ( ; r != NULL; r = r->next) {
    359344                        sdp_record_t *rec = (sdp_record_t*) r->data;
    360345
     
    368353
    369354                                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);
    373358
    374359                                logging_info("Remote peer name is: " << name);
     
    379364                                // Callback
    380365                                callback->onBootstrapServiceFound(name, info1, info2, info3);
    381 
    382366                        }
    383367                        sdp_record_free(rec);
    384368                }
    385         }
     369        } else {
     370                logging_error("sdp_service_search_attr_req failed with timeout");
     371        }
     372
    386373        sdp_list_free(response_list, 0);
    387374        sdp_list_free(search_list, 0);
    388375        sdp_list_free(attrid_list, 0);
    389376        sdp_close(session);
    390 
    391377}
    392378
     
    395381         * Returns a string holding the bt adress in human readable form.
    396382         */
    397         char *str;
     383        char addr[32] = { 0 };
     384        char str[32] = { 0 };
    398385        ba2str(ba, str);
    399386        string result = str;
Note: See TracChangeset for help on using the changeset viewer.