开发者

Problem with getting list of HCI devices from driver in Android

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)
{
    r开发者_如何学编程es = "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.


Ok, I find the reason: device won't answer to simple user (and doesn't matter what permissions did you ask in program manifest). You can directly speak to device only if you are root (or from kernel mode). That means you cannot use devices directly from general applications. Very sad :(

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜