Linux Command Line Howto Accept Pairing for Bluetooth Device Without Pin

Linux command line howto accept pairing for bluetooth device without pin

Try setting security to none in /etc/bluetooth/hcid.conf

http://linux.die.net/man/5/hcid.conf

This will probably only work for HCI devices (mouse, keyboard, spaceball, etc.). If you have a different kind of device, there's probably a different but similar setting to change.

Bluetoothctl set passkey

Here is what works thanks to kaylum :

$bluetoothctl
[bluetooth]# power on
Changing power on succeeded
[bluetooth]# discoverable on
Changing discoverable on succeeded
[bluetooth]# pairable on
Changing pairable on succeeded
[bluetooth]# agent NoInputNoOutput
Agent registered
[bluetooth]# default-agent
Default agent request successful

Then I pair the raspberry with my phone from the phone.

[NEW] Device XX:XX:XX:XX:XX:XX nameofthedevice
[CHG] Device XX:XX:XX:XX:XX:XX UUIDS:
--UUIDS--
[CHG] Device XX:XX:XX:XX:XX:XX Paired: yes

Bluetooth pairing using fixed PIN on bluez 5

I was able to get this working with the test scripts.

For anyone who is interested to know the details, please refer to my post on Raspberry Pi forum. Below is the link.

https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=195090&p=1221455#p1221455

Getting around pairing pin exchange on an android system without GUI and HAL

I also compiled btmgmt on target. With btmgmt running both on target and host I can start a pairing cycle from console and enter PIN in console.
Looking into the sourceode of btmgmt it seems possible to automate the pairing by watching for MGMT_OP_PIN_CODE_REPLY event and sending MGMT_EV_PIN_CODE_REQUEST to automate it.

Pairing bluetooth devices with Passkey/Password in python - RFCOMM (Linux)

Finally I am able to connect to a device using PyBlueZ. I hope this answer will help others in the future. I tried the following:

First, import the modules and discover the devices.

import bluetooth, subprocess
nearby_devices = bluetooth.discover_devices(duration=4,lookup_names=True,
flush_cache=True, lookup_class=False)

When you discover the device you want to connect, you need to know port, the address and passkey. With that information do the next:

name = name      # Device name
addr = addr # Device Address
port = 1 # RFCOMM port
passkey = "1111" # passkey of the device you want to connect

# kill any "bluetooth-agent" process that is already running
subprocess.call("kill -9 `pidof bluetooth-agent`",shell=True)

# Start a new "bluetooth-agent" process where XXXX is the passkey
status = subprocess.call("bluetooth-agent " + passkey + " &",shell=True)

# Now, connect in the same way as always with PyBlueZ
try:
s = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
s.connect((addr,port))
except bluetooth.btcommon.BluetoothError as err:
# Error handler
pass

Now, you are connected!! You can use your socket for the task you need:

s.recv(1024) # Buffer size
s.send("Hello World!")

Official PyBlueZ documentation is available here



Related Topics



Leave a reply



Submit