LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking > Linux - Wireless Networking
User Name
Password
Linux - Wireless Networking This forum is for the discussion of wireless networking in Linux.

Notices


Reply
  Search this Thread
Old 06-23-2010, 04:55 PM   #1
jhaagsma
LQ Newbie
 
Registered: Jun 2010
Posts: 7

Rep: Reputation: 1
Setting up BlueZ with a passkey/PIN (to be used as headset for iPhone)


Hi,

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:

http://jprvita.wordpress.com/2009/12...4-a2dp-stream/
http://acassis.wordpress.com/2008/02...com-bluetooth/ (in portugese but Google Translate does a good job I think)

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
Code:
# apt-cache policy bluez
bluez:
  Installed: 4.63-2
Currently I have used the following commands (as I cannot seem to make this configuration happen automatically):
Code:
hciconfig hci0 noencrypt
hciconfig hci0 piscan
hciconfig hci0 name MyHeadset

sdptool add a2snk
sdptool search --bdaddr local a2snk

hciconfig hci0 class 0x200404
hciconfig -a
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).

In an effort to use a pin, I found a guide which advises using bluetooth-agent followed by a pin ( http://wiki.debian.org/BluetoothUser ) which I tried:

Code:
# 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/


There also exist numerous guides & threads ( http://www.linuxquestions.org/questi...-think-547891/ ) online that talk of an hcid.conf, but apparently ( https://bugs.launchpad.net/ubuntu/+s...ls/+bug/365779 ) the hcid (and consequently the .conf file) was removed in blueZ 4.x


So my question is:

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
 
Old 06-25-2010, 07:39 AM   #2
Hangdog42
LQ Veteran
 
Registered: Feb 2003
Location: Maryland
Distribution: Slackware
Posts: 7,803
Blog Entries: 1

Rep: Reputation: 422Reputation: 422Reputation: 422Reputation: 422Reputation: 422
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.
 
Old 06-29-2010, 10:09 AM   #3
jhaagsma
LQ Newbie
 
Registered: Jun 2010
Posts: 7

Original Poster
Rep: Reputation: 1
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. Reason: version
 
Old 06-29-2010, 12:06 PM   #4
Hangdog42
LQ Veteran
 
Registered: Feb 2003
Location: Maryland
Distribution: Slackware
Posts: 7,803
Blog Entries: 1

Rep: Reputation: 422Reputation: 422Reputation: 422Reputation: 422Reputation: 422
I'm sorry, you're completely right about Bluez4 not using hcid.conf anymore. Have you tried echoing to your passkey file?

Code:
echo -n "1234" >/etc/bluetooth/passkeys/default
And set the "1234" to whatever PIN you want?
 
Old 06-29-2010, 12:59 PM   #5
jhaagsma
LQ Newbie
 
Registered: Jun 2010
Posts: 7

Original Poster
Rep: Reputation: 1
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.

Last edited by jhaagsma; 06-29-2010 at 01:02 PM.
 
Old 06-29-2010, 03:39 PM   #6
MS3FGX
LQ Guru
 
Registered: Jan 2004
Location: NJ, USA
Distribution: Slackware, Debian
Posts: 5,852

Rep: Reputation: 361Reputation: 361Reputation: 361Reputation: 361
Quote:
Originally Posted by jhaagsma View Post
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.
 
2 members found this post helpful.
Old 06-29-2010, 05:17 PM   #7
jhaagsma
LQ Newbie
 
Registered: Jun 2010
Posts: 7

Original Poster
Rep: Reputation: 1
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

Code:
# 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.
 
Old 06-29-2010, 05:47 PM   #8
MS3FGX
LQ Guru
 
Registered: Jan 2004
Location: NJ, USA
Distribution: Slackware, Debian
Posts: 5,852

Rep: Reputation: 361Reputation: 361Reputation: 361Reputation: 361
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.
 
1 members found this post helpful.
Old 06-30-2010, 10:38 AM   #9
jhaagsma
LQ Newbie
 
Registered: Jun 2010
Posts: 7

Original Poster
Rep: Reputation: 1
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.

The only code snippets I could find were in http://www.kernel.org/doc/ols/2006/o...es-421-426.pdf (below, and from 2006) and http://blogs.gnome.org/jamesh/2006/1...bus-interface/ .

Code:
#!/usr/bin/python 

import dbus 

bus = dbus.SystemBus();
obj = bus.get_object(’org.bluez’,’/org/bluez’)
manager = dbus.Interface(obj,’org.bluez.Manager’)
obj = bus.get_object(’org.bluez’,manager.DefaultAdapter())
adapter = dbus.Interface(obj,’org.bluez.Adapter’)
adapter.SetName(’My Bluetooth dongle’)
(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?
 
1 members found this post helpful.
Old 08-09-2010, 01:51 AM   #10
KrishnaShetty
LQ Newbie
 
Registered: Aug 2010
Posts: 1

Rep: Reputation: 0
Pairing with default pin/passkey

Hi folks,

I am using the BlueZ version 4.47.

I need to write test code to qualify some BlueZ profiles.

I want auto pair with some default pin(like "0000") when test case is executed from the command line. And I don't want to use GUI.

Please tell me whether it is possible? If possible please tell me the steps to achieve the same.


I tried to set default pin in the 'simple-agent', but it doesn't seem to work

thanks,
Krishna
 
Old 12-07-2010, 08:07 AM   #11
Deepak Meti
LQ Newbie
 
Registered: Dec 2010
Posts: 1

Rep: Reputation: 0
Hi ,
Anybody got solution.........?
 
Old 08-17-2011, 03:33 PM   #12
philchetcuti
LQ Newbie
 
Registered: Aug 2011
Posts: 1

Rep: Reputation: Disabled
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
XX:XX:XX:XX:XX:XX 1234

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
 
Old 02-27-2012, 01:08 AM   #13
SuperMa_
LQ Newbie
 
Registered: Feb 2012
Posts: 1

Rep: Reputation: Disabled
Unhappy

Hi jhaagsma:

I am trying BlueZ 4.96, and also meet this problem. Have you find the solutions?

When I try to use simple-agent, the gobject-introspection is really painful, as its Makefile doesn't support cross-compile.So I fail at this way.

Hasn't the problem been solved? Help


SuperMa_
 
Old 04-09-2014, 11:21 AM   #14
jwaters42
LQ Newbie
 
Registered: Apr 2014
Posts: 1

Rep: Reputation: Disabled
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.
  1. I disabled SSP on the Linux device. I ran the following command while configuring my BT adapter:
    Code:
    hciconfig hci0 sspmode 0
  2. I copied simple-agent from the bluez test/ directory to my Linux device.
  3. 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:
    Code:
    from gi.repository import GObject
    with this line:
    Code:
    import gobject as GObject
  4. 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:
    Code:
            def RequestPinCode(self, device):                    
                    print("RequestPinCode (%s)" % (device))      
                    return "1234"
  5. Since I don't want/need keyboard input, I changed the capability to NoInputNoOutput:
    Code:
            capability = "NoInputNoOutput"
  6. 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.
 
Old 07-23-2015, 10:02 AM   #15
guaycuru
LQ Newbie
 
Registered: Jul 2015
Posts: 1

Rep: Reputation: Disabled
Thank you @jwaters42, your answer has helped me a lot.

Please note that step 3 is no longer needed though.

I was successful at running simple-agent but, for some reason, my device still can't connect to my headless system. I'll keep investigating and let everyone know if I have any more to add to this.
 
  


Reply

Tags
bluetooth, bluez, iphone



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bluez passkey-agent, fails ebinjose Linux - Wireless Networking 2 05-18-2010 12:33 AM
Bluetooth headset, Alsa - no soundcard in /proc/asound/cards (but headset works) simopal6 Linux - Hardware 1 04-29-2009 09:07 AM
Issue with BlueZ pin (I think) adriaan.klue Linux - General 2 01-15-2009 08:25 AM
kbluetoothd invalid arguments to passkey sfrdll Linux - Newbie 8 10-15-2007 10:47 AM
CPU 12-V power supply: 4-pin or 8-pin? michapma Linux - Hardware 3 07-23-2007 10:13 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking > Linux - Wireless Networking

All times are GMT -5. The time now is 10:41 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration