LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Bluez Programming - set scan mode with normal user (https://www.linuxquestions.org/questions/programming-9/bluez-programming-set-scan-mode-with-normal-user-739645/)

hadrix 07-12-2009 11:02 PM

Bluez Programming - set scan mode with normal user
 
Hi all.

I have writen a bluez code for setting up bluetooth mode. Here is a function to set the mode to discoverable.

Code:

void discoverable()
{
        int dd, ctl, err;
        struct hci_dev_req dr;
        dd = hci_get_route(NULL);
        dr.dev_id = dd;
        dr.dev_opt = SCAN_PAGE | SCAN_INQUIRY;
       
        ctl = hci_open_dev(dd);
        if (ctl < 0) {
                err = -errno;
                error("Can't open device hci%d: %s (%d)",
                                dd, strerror(errno), errno);
                exit(1);
        }
        if (ioctl(ctl, HCISETSCAN, dr.dev_id) < 0) {
                fprintf(stderr, "Can't set scan mode on hci%d: %s (%d)\n",
                                                dd, strerror(errno), errno);
                exit(1);
        }
}

the output that i got is:
Code:

Can't set scan mode on hci0: Permission denied (13)
I am suspect that it fail to write the mode since it run with normal user. Is there any way to run this function without superuser previlige in the source code?

osor 07-13-2009 05:15 PM

You can use udev to set the permissions of the bluetooth device. In fact, depending on your current rules, all you might need to do is add your user to the bluetooth group.

hadrix 07-13-2009 11:52 PM

Thanks for your reply.I have try to change bluetooth.conf in /etc/dbus-1/system.d from root to normal user from

Code:

<policy user="root">
    <allow own="org.bluez"/>
  </policy>

to

Code:

<policy user="user">
    <allow own="org.bluez"/>
  </policy>

Seems like nothing much changes. Actually how to add user in bluetooth group? Still not know how to add it.


All times are GMT -5. The time now is 06:20 AM.