Setting up BlueZ with a passkey/PIN (to be used as headset for iPhone)
Linux - Wireless NetworkingThis forum is for the discussion of wireless networking in Linux.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
Setting up BlueZ with a passkey/PIN (to be used as headset for iPhone)
I've been trying to connect a phone to a computer to use as a headset, but have been running into a problem with pairing using a pin/passkey. I would like to be able to set up bluez with a passkey that I can connect with, without requiring any setup per device or per connecting time.
There seem to be a few people who have done the headset bit on the web:
Regardless, what I'm attempting to do is to connect to the computer with a device, and then begin streaming the data to it.
My installed version of bluez is 4.63-2
# apt-cache policy bluez
Currently I have used the following commands (as I cannot seem to make this configuration happen automatically):
hciconfig hci0 noencrypt
hciconfig hci0 piscan
hciconfig hci0 name MyHeadset
sdptool add a2snk
sdptool search --bdaddr local a2snk
hciconfig hci0 class 0x200404
which allow me to see it from an iPhone (but not an iPod touch) and a (mac) desktop, and a windows laptop. However, while the mac *seems* to connect without a pin, the phone insists on using a pin. (When I say seems, what I mean is that it says it has paired; but when going to select "Use as audio device", it says the the bluetooth audio has failed; this is a similar experience as on the windows laptop).
# bluetooth-agent 4835
Pincode request for device /org/bluez/1033/hci0/dev_00_14_51_53_6C_AC
Authorizing request for /org/bluez/1033/hci0/dev_00_14_51_53_6C_AC
which works on the mac desktop; it however does not get to the "authorizing request" bit with an iPhone; Furthermore, this is running something from the command line, whereas I would like to initiate connection without having to set anything up on the "headset" computer.
There is a thread on the forums which is related to a passkey-agent, but the program involved does not seem to exist in my setup (or repository), and may have been deprecated, though I've not found anything clear on that point: http://www.linuxquestions.org/questi...-fails-700134/
How do I set a pin without running bluetooth-agent from the CLI, and how do I make it work with an iPhone or other device that insists on using a PIN, with bluez 4.X?
Also, if anyone is knowledgeable about the iPod Touch not seeing items that the iPhone can see, that would also solve a related mystery to me. Or if you know more about the bluetooth -> ALSA step that would be useful
Thanks for your time if you've read this far
Last edited by jhaagsma; 06-23-2010 at 05:18 PM.
Reason: hciconfig hci0 class 0x200404 must be run last or something in this command list resets the class
I think that you can set a PIN in /etc/bluetooth/hcid.conf. Look for the passkey directive and change it to what you would like. You'll probably then have to restart bluetooth to get it picked up, but after that bluetooth should always ask for the PIN.
Thank you for your reply; I had to make sure I wasn't mistaken again before I responded -- but, as I mentioned in my post, it would seem ( https://bugs.launchpad.net/ubuntu/+s...ls/+bug/365779 ) that the hci daemon (and consequently /etc/bluetooth/hcid.conf ) was removed in Bluez 4.
I don't have an hcid.conf, nor does creating one and filling in options do anything at all, unfortunately.
So I guess I'm looking for an equivalent, but for Bluez 4.6x; Surely they can't have *removed* functionality in a new major version, so I assume I simply haven't figured out how to do this; surely somebody has?
Last edited by jhaagsma; 06-29-2010 at 10:11 AM.
It appears I don't have a passkeys folder; when I create one and add a default as you say ( and then /etc/init.d/bluetooth restart ) it still will not use that PIN. I hadn't seen anything on that before, something else to look into though...
Incidentally, a potentially related issue is the fact that when I restart the bluetooth daemon i need to run all those hciconfig commands again to set it up properly. There *has* to be some way to set that automatically. For example, in main.conf it has a Class line, but changing that seems to have no effect on the class. If I change the Class line to 0x200404 in main.conf and restart the bluetooth it still comes up as 0x4a010c (which wasn't even what the class in main.conf was set to originally).
It feels many configuration options were removed, and if these were simply moved somewhere else it was definitely not made obvious.
Surely they can't have *removed* functionality in a new major version
Unfortunately, they did.
You can no longer configure PINs in plain-text files as you could under BlueZ 3.x, as it was seen as a security liability. All pairing must now be done through D-BUS calls, so you need a helper application.
Hrm; it might have been nice had they at least done something like hashed passwords like so many other things. But oh well.
Can everything else not be configured as well?
I haven't really seen any documentation on dbus calls for stuff like that; any ideas on what that would entail? As I posted, I tried using
# bluetooth-agent 4835
where the PIN is 4835. Is this what you mean by a dbus call? (it sounds to me like it is not)
(As mentioned earlier this was only partially successful in one case, as in it connected with a desktop, but not a phone; and further it dropped the connection once I tried to set the item (not even use it) as an audio output device)
Unfortunately, what information have found online regarding BlueZ has been somewhat contradictory, and in large part out of date. The BlueZ wiki which gets referenced occasionally seems to be non-existent at this point (presumably due to becoming out of date), yet Bluez seems to be under active development.
bluetooth-agent is also outdated. The documentation for BlueZ is indeed terrible, it seems like it is intentionally difficult to work with.
If you want to pair a device on the command line, your only option is to use "simple-agent", which is in the /test directory of the BlueZ source. As far as I know it is not included with any BlueZ packages, but I could be wrong on that. It isn't a big deal to pull it from the source tree though.
Hmm I was mainly looking at connecting via the command line for testing purposes; Really, I'd rather have a fixed PIN that I can connect (a phone) to the computer with, without touching the computer at all. If the best way to do this is some other method then I'd prefer to look at that.
(an example of changing the name of the local device into My Blue-tooth dongle using ... Python)
That doesn't seem too bad. I found the API documentation at http://bluez.cvs.sourceforge.net/blu...xt?view=markup which I hope is up to date, though it is from 2008. However, reading through it, it looks like there is no equivalent command to set the PIN or passkey -- lots about passkey agents &etc, which I don't think I fully understand at this point.
I may have to take a peek at that simple-agent. While I realize that my particular application/goal is non-standard, every time I look at this I keep thinking "there has got to be a simpler way to do this." Wishful thinking perhaps?
I realize I'm really late to the thread, but I do have a solution that does not require python or a helper.
What you need to do is create folder /var/lib/bluetooth/XX:XX:XX:XX:XX:XX
The XX:XX:XX:XX:XX:XX is the bdaddr of your bluetooth device which you can find from hciconfig hci0 -a
Inside this folder are many files, I've not fully explored what each does (if they do anything, some do not).
What you need to do is create a pincodes file in this folder.
This is your passkey file, although its not universal, you have to put an entry within it for each bluetooth device you want to connect.
Each entry in the pincodes file is in the format
In this case the XX:XX:XX:XX:XX:XX is the bdaddr of the device you want to pair and the 1234 is your pairing code.
You also must have hcid running to make use of this.
With a little scripting you could grep an hcitool scan and create the appropriate file.
Feel free to email me with any questions, I've been working on an embedded system for the last 20 months that makes heavy use of bluetooth. philip.a.chetcuti<AT>gmail.com
Last edited by philchetcuti; 08-17-2011 at 03:41 PM.
Reason: additional info
I apologize in advance to replying to a post that is over 2 years old, but this thread is still one of the top Google searches for the topic, and after struggling for a few days, I managed to cobble a solution together. Hopefully this helps somebody else trying to accomplish the same thing later.
I'm using BlueZ 4.101. I'm trying to connect my phone/tablet to an Embedded Linux machine to create a PAN. I want the phone/tablet to prompt me to enter a PIN, and I want the Linux device to authenticate against a hard-coded PIN.
Here's how I solved it.
I disabled SSP on the Linux device. I ran the following command while configuring my BT adapter:
hciconfig hci0 sspmode 0
I copied simple-agent from the bluez test/ directory to my Linux device.
I have a minimal file system on the embedded Linux device- my pygobject module is built without instrospection, so I have to disable that in simple-agent. I replaced this line:
from gi.repository import GObject
with this line:
import gobject as GObject
By default, simple-agent requests keyboard input for authentication. My system is headless, and I want it to always authenticate against the same key for each device. So I modified the RequestPinCode method to always return the same value, my PIN:
Since I don't want/need keyboard input, I changed the capability to NoInputNoOutput:
capability = "NoInputNoOutput"
I can now run simple-agent on my device, and the phone/tablet will only pair when the PIN entered matches the hard coded one on the Linux device.
I plan to read the key from a .conf file running on the system instead of hard coding it in simple-agent, but I think there's enough here to get most folks started. The RFS requirements are minimal- a shell (I'm using busybox), bluez, python, dbus-glib, dbus-python, glib2, and pygobject are the only dependencies.