Bluetooth on GhostBSD

Add your Tips and tricks to configure and tweak your GhostBSD System here.
User avatar
NevilleGoddard
Developer
Posts: 517
Joined: Thu Dec 22, 2016 10:30 pm
Location: Japan

Bluetooth on GhostBSD

Post by NevilleGoddard »

I've read in many places on the web that Bluetooth on FreeBSD is broken and unusable.
I was pleasantly surprised to find that this is not the case and Bluetooth works surprisingly well, for transferring files anyway.
I managed to find a Bluetooth 2.0 USB dongle for about $1.50 including postage. Not bad.
I can now successfully send files between my android phone and my computer using Bluetooth.

Insert usb Bluetooth device.

just to be sure:

#kldload ubtbcmfw

Create a config file at /etc/bluetooth

# cd /etc/bluetooth
# touch ubt0.conf
Edit the ubt0.conf file
# ee ubt0.conf
Add these lines to the file:

authentication_enable="YES"
connectable="YES"
discoverable="YES"
role_switch="YES"

Leave the editor. You may need to reboot.


you may want to look in /var/log/messages for something like this:

ubt0: vendor 0x0a12 product 0x0001, rev 1.10/5.25, addr 2
ubt0: Interface 0 endpoints: interrupt=0x81, bulk-in=0x82, bulk-out=0x2
ubt0: Interface 1 (alt.config 5) endpoints: isoc-in=0x83, isoc-out=0x3,
wMaxPacketSize=49, nframes=6, buffer size=294

start the Bluetooth service:

#service bluetooth start ubt0

You may get a warning here like :

/etc/rc.d/bluetooth: ERROR: Unable to setup Bluetooth stack for device ubt0

just try the command again:

#service bluetooth start ubt0

again you may get the same warning but the service may have started anyway.

Next try as normal user to search for nearby Bluetooth devices:

$hccontrol -n ubt0hci inquiry

If Bluetooth is working you'll get your phone discovered and see output like this:


Inquiry result, num_responses=1
Inquiry result #0
BD_ADDR: 11:31:55:90:xx:v8
Page Scan Rep. Mode: 0x1
Page Scan Period Mode: 0x2
Page Scan Mode: 00
Class: 5a:02:0c
Clock offset: 0x1052
Inquiry complete. Status: No error [00]

If you get errors here you're Bluetooth device is probably not supported.

If you just get "Inquiry complete. Status: No error [00]" , turn Bluetooth on on your phone.
Take note of the Bluetooth address - 11:31:55:90:xx:v8 Obviously your number will be different.
To find the name of your phone:

hccontrol -n ubt0hci remote_name_request 11:31:55:90:xx:v8 (use your BD_ADDR)

and you should get:

BD_ADDR: 11:31:55:90:xx:v8
Name: MyPhoneModel

Then edit the /etc/bluetooth/hcsecd.conf file and add these lines or edit on of the example entries that is already there:

device {
bdaddr 11:31:55:90:xx:v8;
name "MyPhoneModel";
key nokey;
pin "1234";
}

The pin can be any number you want "0000" or "1111" are also fine. Use your bdaddr and name

Then :

Turn on authentication:

# hccontrol -n ubt0hci write_authentication_enable 1
# hccontrol -n ubt0hci read_authentication_enable
#hcsecd -d
And pair from your phone. Your bluetooth device should show up in your phone as "yourcomputername(ubt0)". Tap on it and enter the password you put in your hcsecd.conf entry.
If you want to start hcsecd at boot put this into /etc/rc.conf

hcsecd_enable="YES"

Now your phone and computer should be paired. Now to transfer some files. To find the channel your phone uses to transfer files:

#service sdpd start
If you want this to start at boot put into /etc/rc.conf
sdpd_enable="YES"

Now install obexapp

#pkg ins obexapp

then:

start the obex server (as root)

#obexapp -s -C OPUSH

Then as user

$obexapp -c -a 11:31:55:90:xx:v8 -C OPUSH

if the connection is successful, you'll get the obex prompt which means obexapp can send the files you want. You may have to do this command 3 or even 4 times until you get the obex prompt.
When you get the prompt it looks like this:
obex>

Send a file to your phone

obex> put /file/name/youwanttosend

and hit enter and you should get a notification on your phone for accepting incoming bluetooth file.
When you've finished enter di.

obex> di

If you get any errors, make sure you have no quotation marks around the file you're sending and the file name has no gaps. i.e. /home/username/Pictures/my image.jpg will not be sent but /home/username/Pictures/myimage.jpg will.

To send from your phone to computer, make a folder at /var/spool/ called obex

#mkdir /var/spool/obex

And send file from phone to computer, choosing the yourcomputername(ubt0) device. You'll see the file at /var/spool/obex

If you want to send files automatically without all the obexapp commands, use the script here :

[BEGINNING OF SCRIPT]

#!/bin/sh
# $FreeBSD$

# PROVIDE: obexapp
# REQUIRE: LOGIN sdpd

. /etc/rc.subr

name="obexapp"
rcvar=`set_rcvar`
command="/usr/local/bin/${name}"
start_precmd="obexapp_precmd"

obexapp_precmd()
{
rc_flags="-s $rc_flags -C ${obexapp_channel}"

if [ -n "${obexapp_username}" ]; then
rc_flags="$rc_flags -u ${obexapp_username}"
fi

if [ -n "${obexapp_rootdir}" ]; then
rc_flags="$rc_flags -r ${obexapp_rootdir}"
fi
}

load_rc_config $name

: ${obexapp_enable="NO"}
: ${obexapp_flags="-S"}
: ${obexapp_channel="OPUSH"}
: ${obexapp_username="yourloginname"}
: ${obexapp_rootdir="/some/directory/"}

run_rc_command "$1"


END OF SCRIPT

Copy into your favourite text editor (pluma or mousepad) and call it obexapp.sh



In the section

: ${obexapp_enable="NO"}
: ${obexapp_flags="-S"}
: ${obexapp_channel="1"}
: ${obexapp_username=""}
: ${obexapp_rootdir=""}

edit the channel number, obexapp_username to your login name and obexapp_rootdir to wherever you want the files sent from your phone to go to. e.g /home/yourloginname/obex. Save the file and copy it to

/usr/local/etc/rc.d/

#cp /path/to/downloaded/obexapp.sh /usr/local/etc/rc.d/

chmod it to make it executable:

#chmod 577 /usr/local/etc/rc.d/obexapp.sh

Then add these to /etc/rc.conf

obexapp_enable="YES"
obexapp_username="yourloginname"
obexapp_rootdir="/home/yourloginname/obex"

also make sure devd_enable="YES" is also in /etc/rc.conf. This will start Bluetooth on boot up.

Start the script:

# /etc/rc.d/sdpd onestart
# /usr/local/etc/rc.d/obexapp.sh start

Now you should be able to send file from your phone without any commands at all.

To send file to your phone, make this script:
Copy these lines to a mousepad (or other text editor) file:

#!/bin/sh
obexapp -c -a 11:31:55:90:xx:v8 -C 1

Again edit bdaddr and channel number for your phone and save in your home folder or wherever you like and give it any name you like i.e. transfer

Make it executable:

#chmod 755 /path/to/file/transfer

Now to begin transferring files, run the script:
Open a terminal and type as user:

./transfer

Again do this until you get the obex prompt. Usually you only need to do it once, but sometimes it takes 3 times.

obex >

Then use the put command to send files. :mrgreen:

obex> put /your/file/name

I've found sending files to be a little slow as I'm using Bluetooth version 2.0 but 4.0 is much faster. I'm wauting for the device and I'll test it when it comes. Also obexapp won't send odt files but will send mp4, mp3 and jpg files. :D
User avatar
ericbsd
Developer
Posts: 2052
Joined: Mon Nov 19, 2012 7:54 pm

Re: Bluetooth on GhostBSD

Post by ericbsd »

Nice I might look to integrate that in the next release.
User avatar
NevilleGoddard
Developer
Posts: 517
Joined: Thu Dec 22, 2016 10:30 pm
Location: Japan

Re: Bluetooth on GhostBSD

Post by NevilleGoddard »

Thanks ericbsd. I can't wait to test GhostBSD12.

Have you tried this on TrueOS?
I've tried it on FreeBSD 12 and I can transfer files from my computer to my phone, but to transfer files from phone to computer doesn't work anymore unless I run the command

obexapp -c -a 24:31:84:90:11:22 -C 5

then it will work. Maybe because I'm using CURRENT. I don't know.

Is there any way to get this command to start automatically at boot time?
User avatar
NevilleGoddard
Developer
Posts: 517
Joined: Thu Dec 22, 2016 10:30 pm
Location: Japan

Re: Bluetooth on GhostBSD

Post by NevilleGoddard »

Just a quick update.

It looks like bluetooth 4.0 is supported under GhostBSD/FreeBSD.

I've tested a couple of Bluetooth 4.0 dongles and they work quite well. Probably a little better than the Bluetooth 2.0 dongles I tested before.

So far all dongles I've bought have worked. They are very cheap. Only around $5 US. However 4.0 speed is apparently much faster than 2.0 but it didn't seem to be a lot faster. I'll need to test more.

The latest dongles both had the same chip set, unfortunately. I was hoping to try a couple of different chip sets.

The chip is a CSR8510 A10. CSR stands for Cambridge Silicon Radio.

Apparently the Broadcom Corp BCM20702A0 also works.
gbar
Posts: 40
Joined: Wed Apr 05, 2017 12:30 pm

Re: Bluetooth on GhostBSD

Post by gbar »

Hi,

How do i enable Bluetooth for use with a speaker when the laptop has Bluetooth built in?
ta
User avatar
NevilleGoddard
Developer
Posts: 517
Joined: Thu Dec 22, 2016 10:30 pm
Location: Japan

Re: Bluetooth on GhostBSD

Post by NevilleGoddard »

You can try this:

Enable BlueTooth support: (If IBM machine)

kldload acpi_ibm ; echo 'acpi_ibm_load="YES"' >> /boot/loader.conf
sysctl dev.acpi_ibm.0.bluetooth=1 ; echo dev.acpi_ibm.0.bluetooth=1 >> /etc/sysctl.conf

Ensure kernel module ng_ubt is loaded, though it should be loaded automatically by devd:

kldload ng_ubt (for across reboots sysrc kld_list+="ng_ubt" and sysrc kld_list+="ubtbcmfw"

Ensure bthidd service is enabled and started:

service bthidd start (for activation across reboots rc-update add bthidd)

Ensure hcsecd service is enabled and started:

service hcsecd start (for activation across reboots rc-update add hcsecd)
you may also need sdpd

service sdpd start (across reboots rc-update add sdpd)

Put device in pairing mode and pair with GhostBSD. Can be done manually using hccontrol or using bluetooth-config script from Phabricator review

bluetooth-config

Ensure that the connection exists by running hccontrol:

hccontrol -n ubt0hci create_connection BT_ADDR_OF_DEVICE

Verify connection using:

hccontrol -n ubt0hci read_connection_list

Install virtual_oss package:

pkg install virtual_oss

Start virtual_oss:

virtual_oss -C 2 -c 2 -r 48000 -b 16 -s 1024 -R /dev/null -P /dev/bluetooth/BT_ADDR_OF_DEVICE -d dsp

add -T /dev/sndstat before the -d to enable the device to show up in /dev/sndstat. If you want to use the virtual_oss_ctl package to control the virtual_oss device via GUI, add -t vdsp.ctl to the end. If you have trouble, try changing 48000 to 44100.
Play audio via vlc or other app

Further reading:

FreeBSD Handbook Chapter on BlueTooth

Pav's page on BlueTooth that Handbook Chapter was based on. Has some more detail

Review for bluetooth-config script

Review for making /dev/sndstat writeable

PR discussing setup which lead me to this

hccontrol(8) man page

l2ping(8) man page

FreeBSD BlueTooth mailing list archive
User avatar
NevilleGoddard
Developer
Posts: 517
Joined: Thu Dec 22, 2016 10:30 pm
Location: Japan

Re: Bluetooth on GhostBSD

Post by NevilleGoddard »

Also this;

https://www.freebsd.org/cgi/man.cgi?que ... ease-ports

and this for a script that may speed things up:

https://reviews.freebsd.org/D3778
gbar
Posts: 40
Joined: Wed Apr 05, 2017 12:30 pm

Re: Bluetooth on GhostBSD

Post by gbar »

Thanks for the tip,
a bit out of my depth with that! thought it might be a 1, maybe 2 liner!
I'll maybe come back to it when i feel a bit more confident!
User avatar
NevilleGoddard
Developer
Posts: 517
Joined: Thu Dec 22, 2016 10:30 pm
Location: Japan

Re: Bluetooth on GhostBSD

Post by NevilleGoddard »

If you need help or get stuck feel free to ask. Are you new to UNIX?
User avatar
NevilleGoddard
Developer
Posts: 517
Joined: Thu Dec 22, 2016 10:30 pm
Location: Japan

Re: Bluetooth on GhostBSD

Post by NevilleGoddard »

If you need help or get stuck feel free to ask. Are you new to UNIX?
Post Reply