Bluetooth

From SlackWiki
Jump to navigation Jump to search


Introduction

This tutorial is meant to simplify the process of configuring a GNU/Linux Distribution, specifically Slackware, to use Bluetooth wireless technology. I will show you step by step how I setup my system and got Bluetooth functioning. Since it is unlikely that you have the exact same hardware that I do, you may need to modify a few steps to fit your needs.

Example System Information

This is a list of my specific hardware that applies to this topic. Do not worry if your's is not exactly the same because you can still use this information to guide you through the process.

Motherboard (USB Ports)
MSI Neo4 Platinum/SLI
Bluetooth USB Dongle
Kensington Bluetooth USB Adapter (33085)
Cell Phone
Motorola V551
Slackware-Current (as of 5/31/06)
Kernel 2.6.16.16 (worked on 2.6.15.6 also)

Kernel Configuration

The first step is enabling the drivers for USB and Bluetooth in your kernel. I'm not sure exactly which kernel version began including Bluez Bluetooth drivers, but my 2.6.15.6 kernel had them. From this page, it looks like 2.6.5 did not have Bluetooth drivers and needed to be patched. If you are running an older kernel, follow the directions on that page to apply the Bluez patch. If you are unfamiliar with the kernel configuration/compilation sequence, then check out the Kernel26Compilation tutorial before proceeding.

USB support

For the less-advanced user (like myself), it is safe to go through and answer `M` to everything that you can, and `Y` to everything that can not take `M`. You should not enable any of the "debug" options, I'm not 100% sure why, but I'm pretty sure that these options will give you verbose output that is only needed for kernel hackers. Below, you can see the options I have set in my .config file for my kernel. The options listed are just those that I thought pertained to getting my USB ports working and able to recognize my USB dongle.

#
# USB support
#
CONFIG_USB_ARCH_HAS_HCD=y
CONFIG_USB_ARCH_HAS_OHCI=y
CONFIG_USB=y
# CONFIG_USB_DEBUG is not set
#
# Miscellaneous USB options
#
CONFIG_USB_DEVICEFS=y
CONFIG_USB_BANDWIDTH=y
# CONFIG_USB_DYNAMIC_MINORS is not set
# CONFIG_USB_SUSPEND is not set
# CONFIG_USB_OTG is not set
#
# USB Host Controller Drivers
#
CONFIG_USB_EHCI_HCD=m
CONFIG_USB_EHCI_SPLIT_ISO=y
CONFIG_USB_EHCI_ROOT_HUB_TT=y
CONFIG_USB_ISP116X_HCD=m
CONFIG_USB_OHCI_HCD=y
# CONFIG_USB_OHCI_BIG_ENDIAN is not set
CONFIG_USB_OHCI_LITTLE_ENDIAN=y
CONFIG_USB_UHCI_HCD=y
CONFIG_USB_SL811_HCD=m

Bluetooth support

Again, it is safe to enable everything that says "Bluetooth" as a Module. Below are the options from my .config file that I thought might be relevant.

#
# FIR device drivers
#
CONFIG_USB_IRDA=m
CONFIG_SIGMATEL_FIR=m
CONFIG_NSC_FIR=m
CONFIG_WINBOND_FIR=m
CONFIG_TOSHIBA_FIR=m
CONFIG_SMC_IRCC_FIR=m
CONFIG_ALI_FIR=m
CONFIG_VLSI_FIR=m
CONFIG_VIA_FIR=m
CONFIG_BT=m
CONFIG_BT_L2CAP=m
CONFIG_BT_SCO=m
CONFIG_BT_RFCOMM=m
CONFIG_BT_RFCOMM_TTY=y
CONFIG_BT_BNEP=m
CONFIG_BT_BNEP_MC_FILTER=y
CONFIG_BT_BNEP_PROTO_FILTER=y
CONFIG_BT_HIDP=m
#
# Bluetooth device drivers
#
CONFIG_BT_HCIUSB=m
CONFIG_BT_HCIUSB_SCO=y
CONFIG_BT_HCIUART=m
CONFIG_BT_HCIUART_H4=y
CONFIG_BT_HCIUART_BCSP=y
CONFIG_BT_HCIBCM203X=m
CONFIG_BT_HCIBPA10X=m
CONFIG_BT_HCIBFUSB=m
CONFIG_BT_HCIVHCI=m
CONFIG_IEEE80211=m
# CONFIG_IEEE80211_DEBUG is not set
CONFIG_IEEE80211_CRYPT_WEP=m
CONFIG_IEEE80211_CRYPT_CCMP=m
CONFIG_IEEE80211_CRYPT_TKIP=m

Now, just compile the kernel and reboot in to it.

Userland

At a bare minimum, you need to install bluez-libs and bluez-utils from http://www.bluez.org. I used the binary package provided by develia.org, but that was before I knew about SlackBuild scripts. If you can not find a SlackBuild script and you do not want to create your own, you should use Checkinstall at the very least.

At this time, you might as well install KDE-Bluetooth, also. I think I grabbed my binary package from LinuxPackages, but that was also before I knew better. You can either grab the source code on it's own from SoureForge or as a part of KDE Extra Gear. Again, use a Slackbuild script or Checkinstall to install these.

For more information on SlackBuild scripts, you can see the following tutorials: SlackBuild Scripts, Writing A SlackBuild_ Script, Slack-desc, Different Approach To Buildscripts, Checkinstall

If you happen to discover that your bluetooth chip is a Broadcom that requires nonredistributable firmware (which necessarily isn't in Slackware), then see Btfirmware-nonfree

Configuration

Now, should have all of the tools you need to start connecting your computer to your bluetooth devices. First, check the status of the bluetooth dongle with hciconfig.

# hciconfig
hci0:   Type: USB
       BD Address: 00:11:22:33:44:55 ACL MTU: 377:10 SCO MTU: 16:0
       UP RUNNING PSCAN ISCAN 
       RX bytes:385 acl:0 sco:0 events:18 errors:0
       TX bytes:322 acl:0 sco:0 commands:18 errors:0

If yours says "UP RUNNING" then you are good to go. If not, you need to bring the interface up.

# hciconfig hci0 up
# hciconfig hci0
hci0:   Type: USB
       BD Address: 00:11:22:33:44:55 ACL MTU: 377:10 SCO MTU: 16:0
       UP RUNNING PSCAN ISCAN 
       RX bytes:385 acl:0 sco:0 events:18 errors:0
       TX bytes:322 acl:0 sco:0 commands:18 errors:0

Since the dongle works, it's time to configure the programs that will make the actual connections. Use your favorite text editor to edit the PIN in /etc/bluetooth/pin:

# gvim /etc/bluetooth/pin

The PIN needs to be all digits. I'm not sure if it needs to be exactly four (4) digits, but four (4) works well. Here is an example:

PIN:1234

Then you need to edit /etc/bluetooth/hcid.conf

#
# HCI daemon configuration file.
#
# HCId options
options {
       autoinit yes;
       #security auto;
       security user;
       pairing multi;
       pin_helper /opt/kde/lib/kdebluetooth/kbluepin;
       #pin_helper /usr/bin/bluepin;
       #pin_helper /usr/bin/pin;
       #dbus_pin_helper;
}
device {
       name "BlueZ %h (%d)";
       class 0x3e0100;
       #pkt_type DH1,DM1,HV1;
       iscan enable; pscan enable;
       lm accept;
       lp rswitch,hold,sniff,park;
       # Authentication and Encryption (Security Mode 3)
       #auth enable;
       #encrypt enable;
}

Choosing a PIN Helper

From all the other HOWTO's I read, I got the impression that the /usr/bin/bluepin script supplied with the Bluez-utils was junk. I found a nice, simple replacement script on this page http://orin.meinlschmidt.org/~znouza/doc/r51/. I will duplicate it here just for ease, but all rights and respect go to whoever made that page. Use your favorite text editor and create the new file /usr/bin/pin:

#!/bin/bash
# original script from http://orin.meinlschmidt.org/~znouza/doc/r51/
cat /etc/bluetooth/pin

when you are done editing, save and close the file, then make it executable. Choose your permissions wisely.

# chmod 710 /usr/bin/pin
# ls -la /usr/bin/pin
-rwx--x--- 1 root root 35 2006-04-09 19:19 /usr/bin/pin

This /usr/bin/pin script will suffice for pretty much any way you want to connect to your phone. If you want to use kdebluetooth to connect to your phone, then use kbluepin. The example hcid.conf file above is already setup to use kbluepin. To use /usr/bin/pin, simply comment out the kbluepin line and remove the comment character(#) from the /usr/bin/pin line.

Making the Connection

Next, you need to start up the hcid and sdpd daemons. It is a good idea to add these to /etc/rc.d/rc.local so they start automatically with each reboot. At the command line type:

# /usr/sbin/hcid
# /usr/sbin/sdpd

and add these lines to /etc/rc.d/rc.local

/usr/sbin/hcid
/usr/sbin/sdpd

Then, you can set your phone to "discover" mode, allowing other devices to see it is present, and scan for it. On the Motorola V551 you go to Settings > Connection > Bluetooth Link > Setup > Find Me.

# hcitool scan
Scanning ...
       00:12:34:56:78:9A       Motorola Phone

Using the hardware address from the scan above, you can find out a lot of information about your phone.

# sdptool records 00:12:34:56:78:9A
Service Name: Dial-up networking Gateway
Service Description: Dial-up networking Gateway
Service Provider: Cingular
Service RecHandle: 0x10001
Service Class ID List:
  "Dialup Networking" (0x1103)
Protocol Descriptor List:
  "L2CAP" (0x0100)
  "RFCOMM" (0x0003)
    Channel: 1
Language Base Attr List:
  code_ISO639: 0x656e
  encoding:    0x6a
  base_offset: 0x100
  code_ISO639: 0x6672
  encoding:    0x6a
  base_offset: 0xd800
  code_ISO639: 0x6573
  encoding:    0x6a
  base_offset: 0xd803
  code_ISO639: 0x7074
  encoding:    0x6a
  base_offset: 0xd806
Profile Descriptor List:
  "Dialup Networking" (0x1103)
    Version: 0x0100

Service Name: Voice Gateway
Service Description: Headset Audio Gateway
Service Provider: Cingular
Service RecHandle: 0x10003
Service Class ID List:
  "Headset Audio Gateway" (0x1112)
  "Generic Audio" (0x1203)
Protocol Descriptor List:
  "L2CAP" (0x0100)
  "RFCOMM" (0x0003)
    Channel: 3
Language Base Attr List:
  code_ISO639: 0x656e
  encoding:    0x6a
  base_offset: 0x100
  code_ISO639: 0x6672
  encoding:    0x6a
  base_offset: 0xd800
  code_ISO639: 0x6573
  encoding:    0x6a
  base_offset: 0xd803
  code_ISO639: 0x7074
  encoding:    0x6a
  base_offset: 0xd806
Profile Descriptor List:
  "Headset" (0x1108)
    Version: 0x0100

Service Name: Hands-Free voice gateway
Service Description: Hands-Free voice gateway
Service Provider: Cingular
Service RecHandle: 0x10007
Service Class ID List:
  "Handfree Audio Gateway" (0x111f)
  "Generic Audio" (0x1203)
Protocol Descriptor List:
  "L2CAP" (0x0100)
  "RFCOMM" (0x0003)
    Channel: 7
Language Base Attr List:
  code_ISO639: 0x656e
  encoding:    0x6a
  base_offset: 0x100
  code_ISO639: 0x6672
  encoding:    0x6a
  base_offset: 0xd800
  code_ISO639: 0x6573
  encoding:    0x6a
  base_offset: 0xd803
  code_ISO639: 0x7074
  encoding:    0x6a
  base_offset: 0xd806
Profile Descriptor List:
  "Handsfree" (0x111e)
    Version: 0x0101

Service Name: OBEX Object Push
Service Description: OBEX Object Push
Service Provider: Cingular
Service RecHandle: 0x10008
Service Class ID List:
  "OBEX Object Push" (0x1105)
Protocol Descriptor List:
  "L2CAP" (0x0100)
  "RFCOMM" (0x0003)
    Channel: 8
  "OBEX" (0x0008)
Language Base Attr List:
  code_ISO639: 0x656e
  encoding:    0x6a
  base_offset: 0x100
  code_ISO639: 0x6672
  encoding:    0x6a
  base_offset: 0xd800
  code_ISO639: 0x6573
  encoding:    0x6a
  base_offset: 0xd803
  code_ISO639: 0x7074
  encoding:    0x6a
  base_offset: 0xd806
Profile Descriptor List:
  "OBEX Object Push" (0x1105)
    Version: 0x0100

Service Name: OBEX File Transfer
Service Description: OBEX File Transfer
Service Provider: Cingular
Service RecHandle: 0x10009
Service Class ID List:
  "OBEX File Transfer" (0x1106)
Protocol Descriptor List:
  "L2CAP" (0x0100)
  "RFCOMM" (0x0003)
    Channel: 9
  "OBEX" (0x0008)
Language Base Attr List:
  code_ISO639: 0x656e
  encoding:    0x6a
  base_offset: 0x100
  code_ISO639: 0x6672
  encoding:    0x6a
  base_offset: 0xd800
  code_ISO639: 0x6573
  encoding:    0x6a
  base_offset: 0xd803
  code_ISO639: 0x7074
  encoding:    0x6a
  base_offset: 0xd806
Profile Descriptor List:
  "OBEX File Transfer" (0x1106)
    Version: 0x0100

Radio Frequency Communication (RFCOMM)

This is one way to use your phone as a modem. I believe that most Cingular and T-Mobile (GSM/GPRS) in the USA use channel 1 for the Dial-Up Gateway. One way to take advantage of this is to use rfcomm to connect to your phone. In order to do that, you will need to edit /etc/bluetooth/rfcomm.conf:

#
# RFCOMM configuration file.
#
rfcomm0 {
       # Automatically bind the device at startup
       bind yes;
       # Bluetooth address of the device
       device 00:12:34:56:78:9A;
       # RFCOMM channel for the connection
       channel	1;
       # Description of the connection
       comment "Motorola V551";
}

Then connect to the phone by typing:

# rfcomm connect 0

I won't go in to any more details because I don't use my phone as a modem. But, if you want to use your phone that way, there are plenty of resources out there to show you what to do.

KDE Bluetooth

I don't use KDE as my window manager/desktop, but kdebluetooth should automatically run when you start KDE. If you don't use KDE, like me, you can start up the taskbar daemon by typing "kbluetoothd" in a terminal. You can then use the KDE OBEX Push Client to transfer files to your phone. I haven't figured out how to get files off of my phone (like pictures), but I have seen obexftp and obexfs which look promising. When I test those out, I will update this accordingly.

References

http://www.linuxquestions.org/hcl/showproduct.php?product=2879&cat=53

http://www.westmaster.com/zidek/p900/bluetooth/

http://www.bluez.org

http://www.develia.org/tarballs.php?p=networking

http://kde-bluetooth.sourceforge.net/

http://extragear.kde.org/

http://www.gentoo.org/doc/en/bluetooth-guide.xml