Bluetooth with a Nokia cell phone

I have a Nokia 6126 cell phone through AT&T/Cingular Wireless. Like most cell phones it has a camera and can take pictures and record short video clips. It can also use .mp3 files as ringtones. I wanted to transfer files between my computer and my cell phone (without paying text messaging rates to send e-mails back and forth between my phone and computer with attachments). The answer was Bluetooth. . .

Bluetooth is pretty easy to set up on FreeBSD. First, we'll need a Bluetooth adapter. I bought a Jabra A320s USB Bluetooth adapter from an AT&T/Cingular store. I would guess that any standard Bluetooth USB adapter would work, but make no guarantees.

First, as root:

kldload ng_ubt

This will load the Bluetooth kernel module. To load this automatically at startup from now on,

vi /boot/loader.conf

Add the following line:


Now, plug in your USB Bluetooth adapter. It is now time for a little more setup:

cp /usr/share/examples/netgraph/bluetooth/rc.bluetooth /etc/rc.bluetooth
chmod 577 /etc/rc.bluetooth
/etc/rc.bluetooth start ubt0

NOTE: You may receive an error along the lines of Could not execute command "reset". Operation timed out. If that happens, simply repeat the last command:

/etc/rc.bluetooth start ubt0

If all goes well, you should see something like the following:

fongsaiyuk# /etc/rc.bluetooth start ubt0
BD_ADDR: 00:16:38:39:c5:fc
Features: 0xff 0xff 0x8d 0xfe 0x9b 0xfd 00 0x80
<3-Slot> <5-Slot> <Encryption> <Slot offset>
<Timing accuracy> <Switch> <Hold mode> <Sniff mode>
<Park mode> <RSSI> <Channel quality> <SCO link>
<HV2 packets> <HV3 packets> <u-law log> <A-law log> <CVSD>
<Power control> <Transparent SCO data> <Unknown2.7>
Max. ACL packet size: 1017 bytes
Number of ACL packets: 8
Max. SCO packet size: 64 bytes
Number of SCO packets: 0

If you still can't get your USB Bluetooth adapter to work, try the command dmesg and check the output to see if your adapter is showing up at all. Mine looks like this:

ubt0: on uhub0
ubt0: Interface 0 endpoints: interrupt=0x81, bulk-in=0x82, bulk-out=0x2
ubt0: Interface 1 (alt.config 5) endpoints: isoc-in=0x83, isoc-out=0x3; wMaxPacketSize=49; nframes=6, buffer size=294
WARNING: attempt to net_add_domain(bluetooth) after domainfinalize()
WARNING: attempt to net_add_domain(netgraph) after domainfinalize()

Unfortunately, troubleshooting a non-working USB Bluetooth adapter is beyond the scope of this page, so you'll have to turn to other resources (forums, Google, etc.) if your adapter is not recognized.

Now that our Bluetooth adapter is active, it's time to search for our cell phone or other Bluetooth device. Make sure that you set your phone's Bluetooth visibility to "permanently visible" or the equivalent before continuing on to these next steps. Make sure your phone is next to your computer--Bluetooth has a pretty short range.

hccontrol inquiry

This will scan for visible Bluetooth devices. My phone came up as:

fongsaiyuk# hccontrol inquiry
Inquiry result, num_responses=1
Inquiry result #0
        BD_ADDR: 00:17:4b:de:5a:b0
        Page Scan Rep. Mode: 0x1
        Page Scan Period Mode: 00
        Page Scan Mode: 00
        Class: 52:02:04
        Clock offset: 0x5b2a

This same entry may appear multiple times--no reason to be alarmed. The important piece of information gleaned from the inquiry is the BD_ADDR of our Bluetooth device: 00:17:4b:de:5a:b0 (in the case of my particular phone). We will need this information, so write down the BD_ADDR of your phone or other Bluetooth device for future reference.

If you want to see the name of your Bluetooth device (whatever you named it in your phone settings, or the default name if you didn't):

hccontrol remote_name_request 00:17:4b:de:5a:b0

Substituting the BD_ADDR of your particular device instead of mine. This will return something like:

fongsaiyuk# hccontrol remote_name_request 00:17:4b:de:5a:b0
BD_ADDR: 00:17:4b:de:5a:b0
Name: Kevin's Nokia 6126

Great. So we can see our device in FreeBSD. What if we want to transfer files between FreeBSD and the cell phone? To do that we'll have to do a little more configuration, armed with the BD_ADDR of our device:

cp /usr/src/usr.sbin/bluetooth/hcsecd/hcsecd.conf /etc/bluetooth/hcsecd.conf
vi /etc/bluetooth/hcsecd.conf

Add the following lines to the bottom of the file:

device {
        bdaddr 00:17:4b:de:5a:b0;
        name   "Kevin's Nokia 6126";
        key    nokey;
        pin    "1234"

Naturally, substitute the BD_ADDR of your device in place of mine, and pick a PIN that is very easy to remember, such as 1234. We'll need to type this into the phone when we pair our phone and computer. Got more than one Bluetooth device? Simply create a new entry for it underneathe your first entry, following the same format.

Save your changes and exit, then execute the following commands:

hccontrol write_authentication_enable 1
hccontrol read_authentication_enable

We're almost ready to transfer files between our phone and FreeBSD. We just need to install an application called obexapp.

cd /usr/ports/comms/obexapp
make install clean

Once that is installed, it is (finally) time to pair our phone and computer and transfer files:

obexapp -c -a 00:17:4b:de:5a:b0 -C ftrn

If this works, you will see an obex> prompt. Do not get discouraged if the connection does not immediately work. This is what a typical attempt to connect to my cell phone looks like:

fongsaiyuk# obexapp -c -a 00:17:4b:de:5a:b0 -C ftrn
obexapp: Could not obtain RFCOMM channel: Connection reset by peer
fongsaiyuk# obexapp -c -a 00:17:4b:de:5a:b0 -C ftrn
obexapp: Could not obtain RFCOMM channel: Host is down
fongsaiyuk# obexapp -c -a 00:17:4b:de:5a:b0 -C ftrn

Notice that it took me 3 attempts before the connection was established. The first time you connect to your cell phone, before the obex> prompt appears, a message will flash on your cell phone screen asking you if you want to accept a connection from fongsaiyuk.domain.actdsltmp or whatever your computer is named. Choose "Accept" and you will then be prompted to enter your PIN. Enter the PIN you set in /etc/bluetooth/hcsecd.conf, which in this example was 1234, and the obex> prompt should appear in your terminal back on your computer. We are now connected!

An 'ls' will reveal the directory tree of your phone:

obex> ls
Access    Owner    Group    Size       Modified         Name
  R       n/a      n/a      n/a        n/a              Graphics/
RW      n/a      n/a      n/a        n/a              Themes/
  R       n/a      n/a      n/a        n/a              Tones/
  R       n/a      n/a      n/a        n/a              Images/
  R       n/a      n/a      n/a        n/a              Video clips/
  R       n/a      n/a      n/a        n/a              Music files/
  R       n/a      n/a      n/a        n/a              Audio/
Success, response: OK, Success (0x20)

On my Nokia 6126, photos taken with my cell phone's camera are saved to the Images directory, and videos are saved to the Video clips directory. To view/download photos from the phone to computer,

cd Images

Which will show a listing of file names on the phone. To download a particular photo,

get Image000.jpg

Where Image000.jpg is the file name of the photo you wish to download. Unfortunately, wildcards * do not seem to work, so you have to download each photo manually one at a time. The files will be downloaded to whatever directory on your computer you started obexapp from, probably ~/.

To upload a photo from your computer to your phone (i.e. to use as a background),

put /home/reinholz/Documents/Genealogy/media/reinholz_kevin.jpg Image022.jpg

Specifying the file on your computer, with the full path to it, followed by the name you want it to have on your phone. I thought it best to follow the naming convention of the phone, but this may or may not be required depending on your phone's model. Keep in mind the file size of the photo on your computer. You may want to scale it down to match the size and resolution of photos taken with your phone's camera. The Gimp is a nice program for manipulating and scaling images.

To download a video,

cd ..
cd Video\ clips

Same routine. To download a particular video, specify it by name:

get Video000.3gp

On my phone, .mp3 files are stored in the Music files directory:

cd ..
Music\ files

Here's where you can have some fun. Being the true nerd that I am, I thought it would be "cool" to use actual clips from songs as ring tones and to set a different song for each person in my phonebook.

First of all, you need to know what kind of .mp3 your phone will accept. What length, quality, file size, etc. This will probably take some trial and error. I found that my Nokia 6126 would accept a 30 second .mp3 at 64 kbps, 22 kHz. I know, that sounds like very low quality, but on my cell phone's speaker as a ring tone, it sounds perfect. 30 seconds is probably overkill (your phone is never going to ring that long before the call goes into voicemail), so 10 to 15 seconds should be plenty.

You can rip individual tracks off of CDs to .mp3 files using Grip, and use Audacity to choose the 10 to 15 second part of the song you want to use as a ring tone and create a new .mp3 file of the appropriate length and quality. Note that you don't have to rip the CD track to .mp3 with Grip--you could also rip to .ogg or .wav and Audacity will be perfectly happy to import it. The trick is to make sure that you set the .mp3 quality to 64 kbps in Audacity and export to .mp3 when you're done editing your file down to the clip you want to use as a ring tone. Once you have your .mp3 ring tone, you would upload it to your phone just as you would a picture. From within the Music files folder,

put /home/reinholz/Bad\ Religion\ -\ New\ Dark\ Ages\ \(edited\).mp3 darkages.mp3

Same explanation I gave for uploading a photo from your computer to your phone as far as specifying the complete path to the file on your computer followed by the name you want the file to have on your phone.

Every phone is going to have a slightly different way of setting a .mp3 file (if this feature is supported on your phone at all) as a ring tone. On mine, I go to the phonebook, select a name, go to Options, go to Edit, go to Options again, go to Add detail, go to Tone, go to Open Tones & Graphics (as opposed to Ringtones), go to Music files, and select the .mp3 I want to use as a ring tone. Voila. The next time this person calls, their custom song will play instead of your phone's default ring.

When you're finished copying files back and forth between your computer and phone, hit Ctrl+C to close obexapp. If you are finished using Bluetooth, before you unplug your USB Bluetooth adapter, be sure to:

/etc/rc.bluetooth stop ubt0

You can then unplug your Bluetooth adapter. You may also want to set your phone's visibility mode back to Hidden.

This is all great, but do I really have to go through all these steps every time I want to transfer files between my phone and computer? Absolutely not. A lot of this was initial setup, but for the truly lazy, let's create 2 scripts to (1) activate Bluetooth, and (2) connect to our phone using obexapp. As user:

vi ~/bin/bluetooth_startup

Now add the following lines:

/etc/rc.bluetooth start ubt0
hccontrol write_authentication_enable 1
hccontrol read_authentication_enable
exit 0

Save changes and exit. Then, as root:

chmod 577 /home/reinholz/bin/bluetooth_startup

This will make our script executable. Then, as user,

vi ~/bin/kevin_cellphone

And add the following lines:

obexapp -c -a 00:17:4b:db:d1:80 -C ftrn

Substituting of course the BD_ADDR of your phone in place of mine. Save your changes and exit. Don't forget to make this script executable as well. As root:

chmod 577 /home/reinholz/bin/kevin_cellphone

Now when you want to connect to your phone, simply plug in your USB Bluetooth adapter, then, as root:


You may need to execute this command twice before it works. Then, to transfer files between your phone and computer,


Again, it may take a few attempts before the obex> prompt appears. Don't forget to make your phone visible before attempting the connection.

On my phone, I can also choose to automatically accept connections from my computer, fongsaiyuk.domain.actdsltmp. If this is set, I no longer need to enter my PIN on the phone every time I try to connect to it from my computer.

When you're finished with Bluetooth, run:

/etc/rc.bluetooth stop ubt0

Then unplug your USB Bluetooth adapter.