|[software] [catdoc] [tcl] [geography] [old things]
Bluetooth address resolution project for Linux
RationaleOfficial 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:
ArchitectureAs 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 formatSince 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.
libraryHere is Tcl library to scan .btdev files. It provides following commands:
::btdev::byname nameReturns tcl list of device parameters listed above searching by device name. If device is not found, returns empty list
::btdev::byaddr bt-addrDoes the same, but using bluetooth address as key
::btdev::channelbyname name serviceReturns two-element list with bt address as first element and channel as second element for device with given name and given service type.