portrait

Поиск



[software] [catdoc] [tcl] [geography] [old things]

Bluetooth address resolution project for Linux

Rationale

Official Linux Bluetooth stack doesn't include any system-wide way to cache descriptive bluetooth device names and use them instead of numeric addresses.

Caching of names in the computer seems to be neccesary, because most devices are able to operate in non-discoverable mode, and this mode is preferrable due to security reason.

Bluetooth protocol includes "pairing" stage when same secret (typically numeric PIN-code) should be entered on both devices. Since then it is stored (at least in cell phones) along with address of paired devices, and connections may be made even if device is not discoverable.

Evidently, computer should be able to store PIN codes too. Problem is that entering PIN code for some personal device such as cell-phone is evidently end-user action, whereas exchange of PINs is kernel-level activity.

Bluez project provides example implementation of PIN helper program, which requests PIN from user interactively. Unfortunately, this implementation doesn't work on reasonable secure Linux system, because it requires daemon process to make connection to user X server.

There is also dbus-based pin-helper which is better, but doesn't suit my requirements too.

This also has some usability problems:

  • Suppose your bluetooth adapter is plugged into headless linux server on home network. You can execute any bluetooth-related utility via ssh, but there is no local X server to ask PIN on.
  • Suppose you have several computers at you home, and only one have bluetooth adapter plugged in. Suppose it is your girlfriend who is sitting at that computer. Would she like if she would be asked to enter PIN when you are operating with your favorite bluetooth gadget?
  • Last, but not least - why should you remember some cryptic code when you have a computer. If such silly gadget as cell phone can remember them for you, why not computer?

Architecture

As user have to manage his own personal appliances himself, database should be stored in user's home directory. It can be simple text file like /etc/password which lists device name, device address, most interesting channels and pin code. It is strictly personal data, so file would probably have 0600 permissions.

PIN helper utility should scan all user home directories (or all interactively logged in user's directories) and search for appropriate address in their .btdev files. It is running as root, so it would be able to access these files anyway. If eventually, Bluez would use some privilege separation, we can chgrp these files to primary group of the system user pin helper run as.

There should be utility (or several ones - command line, GUI etc) to pair your computer with bluetooth device. It should use hcitool scan command to find out devices you want to pair with, ask your to enter PIN, write it to .btdev file and perform some operation which requires actual connection, such as sdptool browse to check if all is correct.

File format

Since bluetooth addresses are colon-separated, we cannot use colons as field separators in .btdev So, let's use vertical bar. People don't typically put it into device names.

Traditional hash-mark comments should be allowed.

Field list:

  1. Device nickame, as displayed by hcitool scan
  2. Device address
  3. PIN code
  4. various channels. Now following list of channels is used: IRME_SYNC, DUN, OPUSH and FTRN (file transfer)

library

Here is Tcl library to scan .btdev files. It provides following commands:
 ::btdev::byname name
Returns tcl list of device parameters listed above searching by device name. If device is not found, returns empty list
 ::btdev::byaddr bt-addr
 
Does the same, but using bluetooth address as key
::btdev::channelbyname name service
Returns two-element list with bt address as first element and channel as second element for device with given name and given service type.

Utilities