Bluetooth on Ubuntu Linux
— Update 20/10/07 —
Bluetooth on ubuntu and other GNU/Linux GNOME based Distros has really changed since I wrote this, so i’m being a good internet citizen and updating.
For most up todate distros (like Ubuntu Gutsy or Fedora 7) we have the following which will make you life easier and if you haven’t already you should try before attempting anything below.
First of all we have the bluez-gnome which provides:
- Bluetooth Analyzer
- bluetooth-properties
- bluetooth-applet
These utilities allow for pairing or “bonding” of bluetooth devices under the one Bluetooth Analyzer roof and importantly; bluetooth device to desktop with support for Pin authentication (using the passkey agent) once paired or bonded you can use and configure the services which are normally avaliable; audio, input, network and serial services.
Second bluz-utils which provides:
- passkey-agent (yes actually compiled now)
- other kernel/low level bluetooth stuff
Third gnome-bluetooth which provides:
- gnome-obex-send
- gnome-obex-server
These allow you to “on the fly” send and recive files to a bluetooth enabled device, the easiest way to utilise this is by installing nautilus-sendto which allows you to right click any file in nautilus and the “send to” and hopefully then to your bluetooth device. If all of that functionality wasn’t enough check out Gnome’s Phone Manager; gnome-phone-manager and gnokii –End Update–
Here is how to get a bluetooth remote desktop control working in ubuntu and possibly other Linux distros using a mobile phone or other bluetooth device.
This has been tested today with a sony ericson k800i (thanks Dave) and 09/04/07 with a w810i (thanks Andrew)
This allows you to use your phone or other bluetooth enabled device as an input device, most commonly as a mouse.
To do this you will need:
1) A bluetooth enabled device with remote controlling software on it
2) A computer with bluetooth capabilities (e.g. a bluetooth dongal)
3) These packages installed: bluetooth bluez-pin bluez-utils gnome-bluetooth nautilus-sendto libddus-1-dev build-essential
4) patience
5) sticky back plastic and old egg boxes
Ok now we have all that in order.. we’ll actually need to go and enable HIDD open up /etc/default/bluetooth with your favorite editor (it’ll need to be running as sudo or root) and change:
HIDD_ENABLED=0 to
HIDD_ENABLED=1
For the HIDD options it is worth taking note of their comment on “remote –master if you’re having trouble…..”.
Now here is the bit that throws most people off… the phone I was using was able to get as far as putting in the pin/pass key/pass code/password for the bluetooth connection but failed on connect, this was because of this error:
hcid[ ]: pin_code_request (sba=AA:BB:CC:DD:EE:FF, dba=AA:BB:CC:DD:EE:FF)
hcid[ ]: call_passkey_agent(): no agent registered
I suggest you have a terminal window open running “tail /var/log/syslog -f” so that you can keep an eye on what is going on, most of the error messages or successs messages will be sent to this log.
The passkey (pin agent/pass code/password) does not come installed or running with bluez-utils, You’ll need to do that your self.
it’s located in /usr/share/doc/bluez-utils/examples/ . In this folder you should find two files: Makefile and passkey-agent.c.gz IF you have passkey-agent.c in there (note without the gz on the end) ignore the zcat step 3.
To build and install passkey-agent
1) copy the files to a tempory directory e.g. mkdir /tmp/bluetooth/ && cp /usr/share/doc/bluez-utils/examples/* /tmp/bluetooth/
2) change directory to the bluetooth directory. e.g. cd /tmp/bluetooth3) uncompress the passkey-agent.c.gz by doing zcat passkey-agent.c.gz >> passkey-agent.c . If you don’t do that you’ll get this error:
make: *** No rule to make target `passkey-agent.c’, needed by `passkey-agent’. Stop.
4) now type “make” to compile the c code of passkey-agent.c
5) you should now have in your /tmp/bluetooth/ directory :
Makefile passkey-agent passkey-agent.c passkey-agent.c.gz
6) Copy “passkey-agent” to /usr/local/bin/
7) create a passkey (or pin as phones call them) using your favourite text editor (it will need to be run as sudo or root)
save the code in a file called /etc/bluetooth/pin
e.g: 1234
Nothing else in this file !
8) now create an executable which will be able to spit out this number:
create a file in /usr/local/bin/ called bluepincat
so with your favorite text editor (again as root or sudo) put this in the /usr/local/bin/bluepincat
#!/bin/sh echo -n "PIN:" cat /etc/bluetooth/pin
Connecting the Device
1) run in a terminal:
passkey-agent --default /usr/local/bin/bluepincat
2) also run:
sudo hidd --connect AA:BB:CC:DD:EE:FF
Where AA:BB:CC:DD:EE:FF is the mac address of your phone. Obtained via the dba= part in your syslog or from from: hcitool scan. This may need to be run as root or sudo.
Something like this should come up in your syslog:
hcid[12813]: name_listener_add(:1.61)
hcid[12813]: Default passkey agent (:1.61, /org/bluez/passkey_agent_13795) registered
hcid[12813]: pin_code_request (sba=AA:BB:CC:DD:EE:FF, dba=AA:BB:CC:DD:EE:FF)
hcid[12813]: Calling PasskeyAgent.Request: name=:1.61, path=/org/bluez/passkey_agent_13795
hcid[12813]: link_key_notify (sba=AA:BB:CC:DD:EE:FF, dba=AA:BB:CC:DD:EE:FF)
Once you’ve paired or connected you don’t actually need the passkey-agent running until you wish to reconnect, though i’d leave it running while you’re playing about.
Once you’ve got bored of that, take out your egg boxes and sticky back plastic and make a scale model of St.Pauls Cathedral.
Trouble shooting
useful tools, in a command line/terminal type: hcitool scan
This scans bluetooth devices in your area and displays the MAC address of them, (in this blog i’ve shown mine as AA:BB:CC:DD:EE:FF)
This can be useful because at various stages as you can specify MAC addresses for example in the /etc/default/bluetooth configuration file.
You’re getting this error in the syslog:
hidd[ ]: Rejected connection from unknown device AA:BB:CC:DD:EE:FF
where AA:BB:CC:DD:EE:FF is the MAC address of the device that you’re trying to use as the remote control..
Yeah.. I had this problem, unfortunately I’m not sure how i solved it, it may have been this from doing this: sudo hidd –connect AA:BB:CC:DD:EE:FF
- Try changing the HIDD_OPTIONS it in the /etc/default/bluetooth as suggested by the comments in this file regarding the ericson phones.
- Try putting the MAC address on the end of the passkey-agent command.
- Try restarting the bluetooth services via the command sudo /etc/init.d/bluetooth restart
March 26th, 2007 at 7:52 am
The back is not nautlius-sendto it is nautilus-sendto.
and proof read this as it repeats over heh
Good guide otherwise.
March 26th, 2007 at 6:28 pm
Thanks, probably shouldn’t have written this at 3:32am , formatting needs tidying too
April 7th, 2007 at 12:37 pm
passkey-agent “0000″ 00:19:63:02:8D:13
Passkey service has been released
process 7711: Applications must not close shared connections - see dbus_connection_close() docs. This is a bug in the application.
D-Bus not built with -rdynamic so unable to print a backtrace
Aborted
everytime I try to connect can you help me ?
April 9th, 2007 at 12:51 pm
Hmm i’ve not see that before. try asking on the bluez user mailing list. http://www.bluez.org/contact.html
July 9th, 2007 at 12:22 pm
I get the same error you mention above:
hidd[ ]: Rejected connection from unknown device AA:BB:CC:DD:EE:FF
Then I tried the python script here http://wiki.bluez.org/wiki/HOWTO/Authorization which works flawlessly.
Since I am using Gentoo there is no /etc/default/blue-something and since bluez-libs-3.x I can’t find anything like HIDD_OPTIONS cause the new hidd is called hcid and doesn’t have so many options.
Any suggestions for the new version?
September 18th, 2007 at 2:36 pm
[…] The above is condensed from these pages, first second […]
November 8th, 2007 at 4:05 pm
Thanks. This blog was a great help.