Dominique Meeùs, retour au sommaire Linux
Dernière modification le
Current distributions should have no trouble handling Bluetooth setup:
simply attach the USB dongle and launch the Bluetooth system by entering /etc/init.d/
bluetooth start (Suse and Fedora) or /etc/ init.d/bluez-utils (Ubuntu). Suse
Linux 9.3 actually enables Bluetooth services automatically as soon as you attach an adapter.
Typing hcitool dev will tell you if Linux has correctly identified your dongle. The
output from this command should show you the connected device and its Bluetooth address:
marcel@kim:~> hcitool dev
Devices:
hci0 00:10:C6:29:2E:15
You can then enter hcitool scan to check for your mobile phone.
Note that simply enabling Bluetooth on your mobile will not get your very far. The phone has to
be in visible mode. The following example shows that the program has detected both the phone
(Z1010) and a PC (ubuntu-0):
marcel@kim:~> hcitool scan
Scanning ...
00:0E:07:BF:B4:C4 Z1010
00:04:61:81:5C:6B ubuntu-0
The last step is to set up a serial connection with the mobile; you need to
be root for this. Again, you will need to run hci tool scan; note the Bluetooth
address for the phone (watch out for the additional null between bind and the
address):
rfcomm bind 0 00:0E:07:BF:B4:C4
If this command returns Connection refused, you probably need
to pair the phone with your PC. To do so, enter a four (or more) digit PIN code in
/etc/bluetooth/pin. Make sure the file contains only the PIN code. Then restart the
Bluetooth service and launch your mobile phone’s Bluetooth device search function. If the phone
prompts you for the PIN code, enter the code from /etc/bluetooth/pin.
To test the connection, become root and enter minicom -s;
select /dev/rfcomm0 as the port, and set the speed to 115200 baud. Now
type the AT command ATI to output your mobile phone name.
The rfcomm command shows you the active connections. To close
the connection to the PC, again become root and enter rfcomm release 0.
Access Privileges: To open a connection with
rfcomm, you must be root. Of course, you will want to access the serial
Bluetooth port using a normal user account. To do so, first modify the permissions for
/dev/rfcomm0. For older Linux distributions that do not use dynamic device files,
simply type chmod 666 /dev/rfcomm0 to do this. More recent distributions create the
device file on- the-fly when a Bluetooth adapter is connected. In this case, you can either reset
the file permissions every time you attach a Bluetooth device, or change the Udev settings for
the device.
To do so, open the /etc/udev/rules.d/50-udev.rules file in your
editor, and add the following line (Suse Linux 9.3):
KERNEL="rfcomm*", NAME="%k" GROUP="uucp" MODE="0660"
OPTIONS="resmgr"
For Suse Linux 9.2, open
/etc/udev/permissions.d/udev.permissions in the editor and add the following
line:
rfcomm*:root:users:0666
Ubuntu already has a line that starts with rfcomm[0-9]*. In
this case, you can simply set the permissions to 0666. Users with Fedora Core 3
don’t need to make any changes. The /dev/rfcomm0 automatically belongs to the logged
on user in this case.
Automating connections: To remove the need to type the
bind command manually, you can tell the Bluetooth system to bind automatically. To
do so, edit the /etc/bluetooth/rfcomm.conf file. Change the bind no;
entry to bind yes;, and enter your phone’s Bluetooth address in device
11:22:33:44:55:66;, for example:
device 00:0E:07:BF:B4:C4;
Remove the hash sign at the start of the line, if any.