Thursday, November 29, 2007

How to do bluetooth pairing in Linux?

Pairing
Most bluetooth devices require pairing to be performed before a Bluetooth connection is established. Desktop computer or any remote device may initiate pairing to other bluetooth devices.

When the computer starts pairing, usually the outgoing connection is performed by pin_helper program (usually bluepin), which will show a graph of the dialog box asking the user to enter a PIN, which must match with the serial code on the remote device. If the serial code on the remote devices match, then the remote device is required to provide a PIN that match with the contents of /etc/Bluetooth/pin file.

In some Linux distributions, the PIN is set to the string alphabetical in the BlueZ. This is may cause inconveniences as many Bluetooth devices, including most cell phones are only capable of delivering digital PIN. It is therefore recommended that you change the contents of /etc/Bluetooth/pin to reflect a numeric code.

If pairing is successful, the hcid demon stores the resulting link key used to authenticate all future relations between the two devices involved in the /etc/Bluetooth /link_key database file.

Pinging a remote device
The ping command is a great useful utility to know if remote computers are able to be connected on a TCP/IP network. BlueZ has an analog to ping, called l2ping. Its name related to the fact that it creates a connection to the bluetooth device using the logical link control and adaptation protocol (L2CAP), the lowest-level link-based protocol in Bluetooth.

Therefore, before you feel despair because you cannot connect to a bluetooth device, you may check it with l2ping. There could be an error with software higher up the chain; l2ping allows you to check if a connection can be established with a remote bluetooth device. Here's an example of l2ping in operation (you must to run l2ping as root user):

# l2ping 00:0A:D9:15:CB:B4
Ping: 00:0A:D9:15:CB:B4 from 00:80:98:24:15:6D (data size 20) …
0 bytes from 00:0A:D9:15:CB:B4 id 200 time 54.85ms
0 bytes from 00:0A:D9:15:CB:B4 id 201 time 49.35ms
0 bytes from 00:0A:D9:15:CB:B4 id 202 time 34.35ms
0 bytes from 00:0A:D9:15:CB:B4 id 203 time 28.33ms
4 sent, 4 received, 0% loss

No comments: