Difference between revisions of "How to setup Bluetooth"

From ThinkWiki
Jump to: navigation, search
(Configuring the kernel)
(Serial connection over Bluetooth)
Line 33: Line 33:
  
 
==Serial connection over Bluetooth==
 
==Serial connection over Bluetooth==
One of the reasons for getting that bluetooth connection up was to be able to use GPRS or 3G (UMTS) for connecting my laptop to internet. I was googling a bit on it, and I was pretty surprised to learn that one should communicate with the modem using AT-commands - that's stuff we did in the previous millenium, causing our modems to make lots of fancy sounds.  By configuring /etc/bluetooth/rfcomm.conf correctly, I got a device /dev/rfcomm0 - eventually one could use the command:
+
One of the applications you might want to connect your phone for is to use GPRS or 3G (UMTS) for connecting to the internet. A lot of phones do this through using AT-commands on a serial over Bluetooth connection.
  
:rfcomm bind 0 00:15:A0:7A:90:F2 3
+
By configuring {{path|/etc/bluetooth/rfcomm.conf}} correctly, you'll get a device {{path|/dev/rfcomm0}}.
  
Where the HW address should be replaced with that of your phone - if you don't know the hardware address of your phone yet, you can find it running:
+
Eventually one could use the command:
:hcitool scan
+
:{{cmdroot|rfcomm bind 0 00:15:A0:7A:90:F2 3}}
and '3' is the channel to use.  I spent quite some time fighting before I found out of that one; I didn't find it documented anywhere, but by running
 
:sdptool records 00:15:A0:7A:90:F2
 
I found channel 3 to be the right one for my phone.  You will have to experiment to find the right one for your phone setup; for T-Mobile GSM/GPRS carrier in USA this is channel 1.  By experimenting, I managed more or less to crash the bluetooth stack on the cellphone so it had to be rebooted.
 
  
Now that /dev/rfcomm0 exists.
+
The hardware address should be replaced with that of your phone. If you don't know the hardware address of your phone yet, you can get it by running:
 +
:{{cmdroot|hcitool scan}}
  
At this point you can use an automatic dialing utility such as wvdial, editing the config file to point to the modem at /dev/rfcomm0, and everything should work just like a land line!
+
The last parameter ('3') is the channel to use. I spent quite some time fighting before I found out of that one; I didn't find it documented anywhere, but by running
 +
:{{cmdroot|sdptool records 00:15:A0:7A:90:F2}}
 +
I found channel 3 to be the right one for my phone.  You will have to experiment to find the right one for your phone setup; for T-Mobile GSM/GPRS carrier in USA this is channel 1.
 +
{{NOTE|By experimenting, the bluetooth stack on the cellphone may crash. Reboot it if that happens.}}
 +
 
 +
Now {{path|/dev/rfcomm0}} exists.
 +
 
 +
At this point you can use an automatic dialing utility such as wvdial, editing the config file to point to the modem at {{path|/dev/rfcomm0}}, and everything should work just like a land line!
  
 
You may directly access the modem (i.e. by using minicom:)
 
You may directly access the modem (i.e. by using minicom:)
:minicom -s
+
:{{cmduser|minicom -s}}
set the serial device to be '/dev/rfcomm0', chose 'exit' and then the AT-commands can be typed in. With my operator (Telenor, Norway) it seemed simple enough, I just entered  
+
set the serial device to be {{path|/dev/rfcomm0}}, choose 'exit' and then the AT-commands can be typed in.
 +
With my operator (Telenor, Norway) it seemed simple enough, I just entered  
 
:ATDT *99#
 
:ATDT *99#
 
and lots of cryptic letters started dancing across the screen, indicating a ppp session startup.
 
and lots of cryptic letters started dancing across the screen, indicating a ppp session startup.
  
Then, to run pppd - I created /etc/ppp/peers/nokia with particularly those lines:
+
To configure pppd create {{path|/etc/ppp/peers/nokia}} with particularly those lines:
:/dev/rfcomm0
+
/dev/rfcomm0
:connect '/usr/sbin/chat -v -f /etc/ppp/chat-nokia'
+
connect '/usr/sbin/chat -v -f /etc/ppp/chat-nokia'
:debug
+
debug
:10.0.1.3
+
10.0.1.3
:crtscts
+
crtscts
:noipdefault
+
noipdefault
:ipcp-accept-local
+
ipcp-accept-local
:defaultroute
+
defaultroute
:novj
+
novj
:nobsdcomp
+
nobsdcomp
:novjccomp
+
novjccomp
:nopcomp
+
nopcomp
:noaccomp
+
noaccomp
:usepeerdns
+
usepeerdns
  
and a simple /etc/ppp/chat-nokia
+
Furthermore, you need a simple chat script. Create {{path|/etc/ppp/chat-nokia}}:
:'TIMEOUT' '5'
+
'TIMEOUT' '5'
:'ABORT' 'BUSY'
+
'ABORT' 'BUSY'
:'ABORT' 'ERROR'
+
'ABORT' 'ERROR'
:'ABORT' 'NO ANSWER'
+
'ABORT' 'NO ANSWER'
:'ABORT' 'NO CARRIER'
+
'ABORT' 'NO CARRIER'
:'ABORT' 'NO DIALTONE'
+
'ABORT' 'NO DIALTONE'
:'ABORT' 'Invalid Login'
+
'ABORT' 'Invalid Login'
:'ABORT' 'Login incorrect'
+
'ABORT' 'Login incorrect'
:'' 'ATZ'
+
'' 'ATZ'
:'OK' 'ATDT*99#'
+
'OK' 'ATDT*99#'
:'~--' ''
+
'~--' ''
  
and then I entered
+
Run pppd with:
:pppd call nokia
+
:{{cmduser|pppd call nokia}}
and I got Internet.
+
This should establish the internet connection.
  
Different network operators may require different call strings. For many carriers (including T-Mobile USA) "*99#" works without additional parameters.
+
{{NOTE|Different network operators may require different call strings. For many carriers (including T-Mobile USA) "*99#" works without additional parameters.}}
  
 
For editing phonebook / ringtones / etc., the gammu utils (http://www.gamu.net) has been reported to work well, but this appears to be primarily for Nokia phones.
 
For editing phonebook / ringtones / etc., the gammu utils (http://www.gamu.net) has been reported to work well, but this appears to be primarily for Nokia phones.

Revision as of 10:26, 6 January 2006

This is a subjective story about my experiences connecting a ThinkPad T43 running Gentoo and a Nokia N70 using Bluetooth, but I suppose most of the stuff here is generic stuff about how to connect laptops with linux with cellphones using bluetooth.

The kernel used was 2.6.14-gentoo, patched up to get the SATA working after suspend-to-memory.

BlueZ Installation

First of all, installation of Bluez; the following gentoo ebuilds was installed:

  • net-wireless/bluez-bluefw
  • net-wireless/bluez-firmware
  • net-wireless/bluez-hcidump
  • net-wireless/bluez-hciemu
  • net-wireless/bluez-libs
  • net-wireless/bluez-utils

net-wireless/bluez-kernel was also installed, but later I read it should not be needed when running 2.6-kernel - it could even be harmful.

Configuring the kernel

Since the Bluetooth card is connected to the USB subsystem, you will need to enable USB support in your kernel:

Device Drivers → USB support → <M>Support for Host-side USB (CONFIG_USB)
Device Drivers → USB support → [*]USB device file system (CONFIG_USB_DEVICEFS)

Choose an appropriate USB host driver, one of:

Device Drivers → USB support → <M>ECHI HCD (USB 2.0) support (CONFIG_USB_EHCI_HCD)
Device Drivers → USB support → <M>UHCI HCD support (CONFIG_USB_UHCI)
Device Drivers → USB support → <M>OHCI HCD support (CONFIG_USB_OHCI)

In the kernel configuration, I turned most of the bluetooth stuff to <M>; it can be found in the Networking section of the linux configuration.

NOTE!
"RFCOMM protocols support" and "RFCOMM TTY support" (CONFIG_BT_RFCOMM and CONFIG_BT_RFCOMM_TTY) have to be built into the kernel (and not as a module), and hence "Bluetooth support" (CONFIG_BT) and "L2CAP" (CONFIG_BT_L2CAP) also have to be configured as built-in.

Make sure that the according modules are loaded:

# modprobe uhci_hcd ; modprobe ehci_hcd

I found an explaination at http://www.gentoo.org/doc/en/bluetooth-guide.xml about how to set up Bluetooth in Gentoo. I followed most of the steps, but be particularly aware of the notes above on kernel configuration.

Serial connection over Bluetooth

One of the applications you might want to connect your phone for is to use GPRS or 3G (UMTS) for connecting to the internet. A lot of phones do this through using AT-commands on a serial over Bluetooth connection.

By configuring /etc/bluetooth/rfcomm.conf correctly, you'll get a device /dev/rfcomm0.

Eventually one could use the command:

# rfcomm bind 0 00:15:A0:7A:90:F2 3

The hardware address should be replaced with that of your phone. If you don't know the hardware address of your phone yet, you can get it by running:

# hcitool scan

The last parameter ('3') is the channel to use. I spent quite some time fighting before I found out of that one; I didn't find it documented anywhere, but by running

# sdptool records 00:15:A0:7A:90:F2

I found channel 3 to be the right one for my phone. You will have to experiment to find the right one for your phone setup; for T-Mobile GSM/GPRS carrier in USA this is channel 1.

NOTE!
By experimenting, the bluetooth stack on the cellphone may crash. Reboot it if that happens.

Now /dev/rfcomm0 exists.

At this point you can use an automatic dialing utility such as wvdial, editing the config file to point to the modem at /dev/rfcomm0, and everything should work just like a land line!

You may directly access the modem (i.e. by using minicom:)

$ minicom -s

set the serial device to be /dev/rfcomm0, choose 'exit' and then the AT-commands can be typed in. With my operator (Telenor, Norway) it seemed simple enough, I just entered

ATDT *99#

and lots of cryptic letters started dancing across the screen, indicating a ppp session startup.

To configure pppd create /etc/ppp/peers/nokia with particularly those lines:

/dev/rfcomm0
connect '/usr/sbin/chat -v -f /etc/ppp/chat-nokia'
debug
10.0.1.3
crtscts
noipdefault
ipcp-accept-local
defaultroute
novj
nobsdcomp
novjccomp
nopcomp
noaccomp
usepeerdns

Furthermore, you need a simple chat script. Create /etc/ppp/chat-nokia:

'TIMEOUT' '5'
'ABORT' 'BUSY'
'ABORT' 'ERROR'
'ABORT' 'NO ANSWER'
'ABORT' 'NO CARRIER'
'ABORT' 'NO DIALTONE'
'ABORT' 'Invalid Login'
'ABORT' 'Login incorrect'
 'ATZ'
'OK' 'ATDT*99#'
'~--' 

Run pppd with:

$ pppd call nokia

This should establish the internet connection.

NOTE!
Different network operators may require different call strings. For many carriers (including T-Mobile USA) "*99#" works without additional parameters.

For editing phonebook / ringtones / etc., the gammu utils (http://www.gamu.net) has been reported to work well, but this appears to be primarily for Nokia phones.

File Transfer

File transfers are accomplished through OBEX transfer, which I believe is basically an FTP over bluetooth connection. Once you have bonded with your phone (yes, I know you love your sexy RAZR, but here I mean paired it with your laptop via bluetooth), you can easily use "obexftp" to transfer files. As an example,

obexftp -b 00:01:02:03:04:05 -l

will list the root directory of the phone with bluetooth address 00:01:02:03:04:05. Refer to the man page for more of the unique commands. What a wonderful interface! Unfortunately there doesn't seem to be a way to get a standard 'ftp' session using familiar commands (e.g. 'mget').

For a more user-friendly experience, you can use the kde tools, just launch

kbtobexclient

for a file browser. In the Location: option put

obex://[00:01:02:03:04:05]

to list the files. Note that the brackets *are* necessary. From there, you can list directories easily and batch download files.

External Links

http://gagravarr.org/series-60/

http://www.polycon.fi/~laa/biblo/linux_gprs.html