I have to work with HCI device of Android, so I try to implement a simple code for get the number of bluetooth device:

...
struct hci_dev_req *dr;

int sk = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
if (sk < 0)
{
    res = "invalid socket";
    goto end;
}

struct hci_dev_list_req *dl = malloc(HCI_MAX_DEV * sizeof(*dr) + sizeof(*dl));
if (!dl)
{
    res = "not enough memory";
    goto end;
}

memset(dl, 0, HCI_MAX_DEV * sizeof(*dr) + sizeof(*dl));

dl->dev_num = HCI_MAX_DEV;
dr = dl->dev_req;

if (ioctl(sk, HCIGETDEVLIST, (void *) dl) < 0)
{
    res = "unable to get device list";
    goto end;
}

if(dl->dev_num == 0)
{
    res = "device list is empty";
    goto end;
}
...

So everytime I got the message "device list is empty". Why can it be? Only permissions I have in program manifest them: BLUETOOTH and BLUETOOTH_ADMIN. And I run the application as simple user and not as root.

Tnx.

没有正确的解决方案

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top