Linux Guide/Linux and Bluetooth

      Forewords

      The following is just a simple example on how to connect a Bluetooth device, in this case a Nokia phone, in a Linux environment.

      For the purpose of this article we assume to have installed Linux Mandrake 10.0 (Kernel 2.6.13, X86) on our computer.

      ↑Jump back a section

      Configuration and Connection

      First we need the Bluez protocol, usually available as a RPM package on your distribution, then we have to start bluetooth service:

      [user@domain.org user]# service bluetooth start
      

      now it's necessary to setup the PIN code and (if you want) the local device name link, for that purpose we edit (e.g. using JOE) the file /etc/bluetooth/hcid.conf:

      [user@domain.org user]# joe /etc/bluetooth/hcid.conf
      

      modify the following excerpts:

      excerpt for PIN:

      # PIN helper 
      pin_helper /etc/bluetooth/mypin.sh;  
      

      where mypin.sh is a file created ad-hoc.

      Excerpt for name:

      # Local device name
      # %d - device id 
      # %h - host name
      name "userdomain (%d)";
      

      N.B.: file mypin.sh contains:

      #!/bin/bash
      echo "PIN:XXX"
      

      where XXXX means your PIN.

      Now it's time to search for devices:

      [user@domain.org user]# hcitool scan
      

      that should returns something like:

      12:34:56:78:90:12 user1
      

      in other words bdaddr (BT address) and device name, please take note of bdaddr, now it's time to discover available services an the remote device and on which channels:

      [utente@dominio.org utente]# sdptool browse 12:34:56:78:90:12
      

      depending on the type of device we are analysing the request returns a long list of profiles, in this case we are interested in the dialup one, so let see it available on channel 1:

      Service Name: Dial-Up Networking
      Service RecHandle: 0x10007
      Service Class ID List:
      "Dialup Networking" (0x1103)
      Protocol Descriptor List:
      "L2CAP" (0x0100)
      "RFCOMM" (0x0003)
      Channel: 1
      Language Base Attr List:
      code_ISO639: 0x454e
      encoding: 0x6a
      base_offset: 0x100
      Profile Descriptor List:
      "Dialup Networking" (0x1103)
      Version: 0x0100
      

      then:

      [user@domain.org user]# rfcomm bind 0 12:34:56:78:90:12 1
      

      in other words I bind a virtual serial port, rfcomm0 (/dev/bluetooth/rfcomm/0), by means of the tool rfcomm to the remote device modem, not connected yet but ready for software's requests, let see:

      [user@domain.org user]# rfcomm show
      

      that results in:

      rfcomm0: 12:34:56:78:90:12 channel 1 clean
      

      BT modem ready as serial peripheral at /dev/bluetooth/rfcomm/0

      No need to mention that you in the meantime have already accepted the connection on your remote device.

      ↑Jump back a section

      Bluetooth device as a modem

      To use this ready to use device as a modem I suggest as dialer the program wvdial, for this purpose we need to edit it's configuration file /etc/wvdial.conf, like this:

      [Dialer Defaults]
      Modem = /dev/bluetooth/rfcomm/0
      Baud = 460800
      Dial Attempts = 1
      Init1 = ATZ
      Init3 = AT+CGDCONT=1,"IP","web.omnitel.it"
      Phone = *99#
      Carrier Check = no
      Stupid Mode = yes
      Username = ""
      Password = ""
      

      N.B.: this example is from a working configuration for Vodafone Italy on a Nokia phone, for different countries/operators/brand configuration, please google with keyword +CGDCONT and operator's name, mostly you need to modify just the string

      Init3 = AT+CGDCONT=1,"IP","web.omnitel.it"
      

      according to your operator's specifications, and

      Phone = *99# 
      

      according to your phone's brand.

      Dialup and connect...:

      [user@domain.org utente]# wvdial
      

      Good Luck!!!

      ↑Jump back a section

      Other useful commands

      • hciconfig
      • hcitool scan
      • hcitool info BT_ADDRESS

      BT_ADDRESS may be like,, 00:89:34:62:67:52

      • l2ping BT_ADDRESS
      • sdptool browse BT_ADDRESS
      • sdptool search DUN
      • hciattach -l
      ↑Jump back a section
      Last modified on 28 December 2009, at 13:10