Bluetooth Setup in Android after Porting

Following is configuration needed to be done to run Bluetooth on fresh android machine(after porting).

1 . set_bluetooth_power(1) – rfkill i.e. set power i.e. write 1 to /sys/class/rfkill/rfkill0/state
this can be done by command line or in bluetooth.c file 
 Make the changes in Bluetooth.c of (system/Bluetooth/bluedroid).Change the state of the rfkill0 to zero before enabling the power to Bluetooth (these changes are specific to chipset).
In bt_enable function copy following (relative to existing code - 3rd line)

if (set_bluetooth_power(0) < 0) goto out;
usleep(1000000); // 1000 ms retry delay
if (set_bluetooth_power(1) < 0) goto out; // This line will is usually present
usleep(1000000); // 1000 ms retry delay

2.Starts Hciattach daemon- Either from command line or Init.rc as service.
#hciattach -s 115200 /dev/s3c_serial1 any 115200 flow
I was using samsung s3c6410 board with broadcom chipset in it.
Note the baud rate and initial speed.The above will be through command line. If you get Device set up complete then you can check if device in running or not using hciconfig command.
In hciconfig if the device is not running m you can give #hciconfig hci0 up    command to attach hci to UART
If you are using Init.rc method then insert following in init.rc file:

service hciattach /system/bin/logwrapper /system/bin/hciattach -s 115200 /dev/s3c_serial1 any 115200 flow
user root
group bluetooth net_bt_admin
disabled
oneshot

service bluetoothd /system/bin/logwrapper /system/bin/bluetoothd -n /etc/bluez/main.conf
socket bluetooth stream 660 bluetooth bluetooth
socket dbus_bluetooth stream 660 bluetooth bluetooth
# init.rc does not yet support applying capabilities, so run as root
# & let hcid drop uid to bluetooth with the right linux capabilities
group bluetooth net_bt_admin misc
disabled

Build the kernel again , for changes to reflect after flashing.

3.  create hci_sock() and send HCIDEVUP command
This step is taken care by code in bluetooth.c file.Following will be present in bt_enable function
ioctl(hci_sock, HCIDEVUP, HCI_DEV_ID);
Note that hciattach.c will contain each of dev type descriptions. You can also use #hciattach -l to view them

4. Starts bluetoothd daemon
If done using init.rc , bluetoothd is started automatically after hciattach daemon get started when clicked from bluetooth settings. Else you use following command:
#start bluetoothd

You can check the processes running at that moment to check the hciattach and bluetoothd services.

Comments

Popular posts from this blog

Android Objective type Question and Answers

Android Questions and Answers for written exams

Core Java -----Question and Answers