2

I've been trying to get BlueZ working on my Ubuntu desktop for a good portion of the day. It just won't work. I can pair my devices successfully to my computer via the system dialogue, but the BlueZ scan never finds anything. Is there an alternative to BlueZ? Is there a way to manipulate a bluetooth device without BlueZ if the device is already paired?

For good measure, this is the code I've been running (http://people.csail.mit.edu/albert/bluez-intro/c404.html#simplescan.c):

 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <sys/socket.h>
 #include <bluetooth/bluetooth.h>
 #include <bluetooth/hci.h>
 #include <bluetooth/hci_lib.h>

 int main(int argc, char **argv)
 {
     inquiry_info *ii = NULL;
     int max_rsp, num_rsp;
     int dev_id, sock, len, flags;
     int i;
     char addr[19] = { 0 };
     char name[248] = { 0 };

     dev_id = hci_get_route(NULL);
     sock = hci_open_dev( dev_id );
     if (dev_id < 0 || sock < 0) {
         perror("opening socket");
         exit(1);
     }

     len  = 8;
     max_rsp = 255;
     flags = IREQ_CACHE_FLUSH;
     ii = (inquiry_info*)malloc(max_rsp * sizeof(inquiry_info));

     num_rsp = hci_inquiry(dev_id, len, max_rsp, NULL, &ii, flags);
     if( num_rsp < 0 ) perror("hci_inquiry");

     for (i = 0; i < num_rsp; i++) {
         ba2str(&(ii+i)->bdaddr, addr);
         memset(name, 0, sizeof(name));
         if (hci_read_remote_name(sock, &(ii+i)->bdaddr, sizeof(name), 
             name, 0) < 0)
         strcpy(name, "[unknown]");
         printf("%s  %s\n", addr, name);
     }

     free( ii );
     close( sock );
     return 0;
 }
dejay
  • 758
  • 2
  • 6
  • 18
  • 2
    The bluez library is mostly a wafer-thin wrapper around driver ioctl calls. You could just make the ioctl calls directly. I did that with python. If that breaks, then it is either the driver's fault, or a limitation of the hardware, (some devices have limited scanning functionality). – swstephe Oct 14 '13 at 03:28
  • Have u tried commands like hcitool scan to search device – ashish Oct 16 '13 at 05:36

2 Answers2

1

I'm using the same code. I went into my phone settings and toggled the setting that allows my phone to be visible to other devices. Then run the program again and it shows up in the list. Hope this helps to at least verify the code is working.

Chuck Claunch
  • 1,624
  • 1
  • 17
  • 29
1

try using bluetooth-internal library. used by btmgmt. It is more structured than hcixxx tools direct hci_xx ioctls.

Just open the src/btmhmt.c and search for scan (or connect or whatever you want).

Although in both cases licensing issue will exists.

Hope this helps.

fadedreamz
  • 1,156
  • 1
  • 10
  • 19