change Bluetooth from master to slave using bluez library

bluetooth, bluez

Solution

From the command line, the way to achieve what you want is to use the #hcitool. However, you must first be connected. Try this sequence:

hcitool cc AA:BB:CC:DD:EE:FF            #Connect to the device
hcitool con                             #To make sure you are in a connection
hcitool sr AA:BB:CC:DD:EE:FF <role>     #switch master/slave role

If the output of "hcitool con" indicates that you are not in a connection, try the following sequence:

hciconfig hci0 sspmode 1
hciconfig hci0 piscan 
sdptool add SP
rfcomm connect /dev/rfcomm0 AA:BB:CC:DD:EE:FF 1 &
hcitool con
hcitool sr AA:BB:CC:DD:EE:FF <role>

The above code is specifically for the serial profile, but it has worked for me on several occasions when 'hcitool cc' failed.

If you want to see the source code for this, open the tools/hcitool.c source file in the bluez directory and navigate to the function:

static void cmd_sr(int dev_id, int argc, char **argv)

This is the function that fires up the sequence for switching between master and slave role. Following this function you can see what exactly happens through the bluez stack.

I hope this helps.

Problem

Description: I have a small in-house device with bluetooth capabilities. At the moment , other devices connect to that box. Requirement: Now we have to make it slave so that it get connected with other devices. I am wondering how to do it ? I don't need source code or anything just your views. Additional Information: The application uses Bluez libraires to send command to firmware/hardware and we extensively use HCItool. Operating system : Fedora. I am also wondering , do I need to change chipset? From google it doesnt look like we need to change it. Any help will be beneficial to us. Thanks

Original source