Bluetooth & D-Bus, January 08

Core libraries and systems
Message
Author
tempestuous
Posts: 5464
Joined: Fri 10 Jun 2005, 05:12
Location: Australia

Bluetooth & D-Bus, January 08

#1 Post by tempestuous »

Note: The bluetooth libraries and utilities in this thread are compatible only with Puppy 3.x and 4.x.
For Puppy 2.x you must use the older ver 2.10 bluetooth libraries contributed by forum member debernardis here -
http://www.debernardis.it/dotpups/experimental_BT_1.pup
D-Bus is not required with these older libraries.

Recent versions of the bluetooth libraries need to bind to the D-Bus subsystem, and this has been problematic.
Forum member giac_fab mentioned that bluetooth works well under XFCE4.4.1, and with this clue I think I have worked out the problem.
D-Bus can be run using two different utilities; dbus-launch and dbus-daemon. I can now say that dbus-launch is no use for bluetooth, because it does not create the necessary PID file and socket file. You must use dbus-daemon to start D-Bus.
So here is how to get the bluetooth/dbus system running:

NOTE: Use the DBus/Bluetooth dotpets from this forum thread. These have been carefully configured with the correct configuration locations.
Other DBus/Bluetooth packages may not work.

First we need to get D-Bus running.

Code: Select all

rm -f /var/run/dbus/*
dbus-uuidgen --ensure
dbus-daemon --system
Load all necessary bluetooth kernel modules -

Code: Select all

modprobe bluetooth
modprobe l2cap
modprobe rfcomm
modprobe hci-usb
EDIT July 2010
In more recent kernels since Puppy 4.3, the hci-usb module has been replaced by the btusb module. Thus replace the last command with -

Code: Select all

modprobe btusb
Now we need to run the Bluetooth Host Controller Interface daemon (hcid). But this process will fork to run in the background, which means that any errors will not be noticed. So it's a good idea to first do this

Code: Select all

hcid -n
You should see something like this -

Code: Select all

# hcid -n
hcid[3005]: Bluetooth HCI daemon
hcid[3005]: Created local server at unix:abstract=/var/run/dbus-it4nWAKmag,guid=f7d18acc9c2cb6e3385394004772417e
Now you know it looks OK, you can terminate the daemon with Ctrl>c, and hcid can be run without the -n switch.
Now start hcid, as well as the Bluetooth Service Discovery Protocol daemon (sdpd). Run these 2 commands -

Code: Select all

hcid
sdpd
Bluetooth (and D-Bus) should now be up and running.
Forum member tantor reports that this command is necessary

Code: Select all

hciconfig hci0 class 0x3e0100
but I found that OBEX file transfer works fine without it.

Now let's fix the configuration file. Open /etc/bluetooth/hcid.conf in geany.
Change "security auto" to "security user"
You will see that the default passkey is "BlueZ". Since this passkey will need to be entered into your mobile device, it's easier if the passkey is numeric, and I prefer to avoid "1234" since many mobile devices use this as a default value. I'm more confident that a connection is successful if it is made with a non-default value. So let's use "2345" for the following examples. Change "passkey "BlueZ";" to "passkey "2345";"

Now there's just one more thing to prepare: the passkey verification daemon. Run this command -

Code: Select all

passkey-agent --default 2345 &
Once a bluetooth connection is successfully established for the first time, your mobile device registers the properties of the Puppy bluetooth connection with your Puppy computer, and passkey-agent is not needed for all subsequent connections.

Put your bluetooth device (mobile phone, PDA, etc) into "discoverable" bluetooth mode, then run this command to find its bluetooth MAC address -

Code: Select all

hcitool scan
The result for my Motorola K1 is "00:17:E3:4B:68:A3"
Now query the capabilities of your device with -

Code: Select all

sdptool browse 00:17:E3:4B:68:A3
Take note of the channel number which corresponds to the bluetooth service you want to use.
The 3 bluetooth services most likely to be useful are:

1) "Dial-up Networking Gateway"
(my Motorola's channel is 1)
This is for GPRS/EDGE connections to a mobile phone. See the HOWTO's by forum members daemon and debernardis here -
http://www.murga-linux.com/puppy/viewto ... 8286#88286
http://puppylinux.org/wikka/ExperimentalBT
Quick summary: Puppy is missing the necessary /dev/rfcomm0 device node, so create it -

Code: Select all

mknod -m 666 /dev/rfcomm0 c 216 0
Now pair the computer to phone, specifying the correct channel for Dial-up Networking Gateway (channel 1 for me) -

Code: Select all

rfcomm bind /dev/rfcomm0 00:17:E3:4B:68:A3 1
Now you need a GPRS chatscript to connect via /dev/rfcomm0

2) "SyncML Data Synchronisation" (or similar)
(my Motorola's channel is 12)
This is for calendar/organiser/addressbook exchange. See "HowTo sychronise J-Pilot with a Palm device via bluetooth" -
http://www.murga-linux.com/puppy/viewto ... 442#173442
It's also possible, in theory, to synchronise to PocketPC/WindowsMobile devices, but I think that some extra libraries are required. John Doe knows more about PocketPC -
http://www.murga-linux.com/puppy/viewtopic.php?t=17440

3) "OBEX file transfer"
(my Motorola's channel is 9)
This is to copy files from/to your Puppy computer, initiated from Puppy. Quick HOWTO: run this command -

Code: Select all

obexftp -b 00:17:E3:4B:68:A3 -l
It's also possible to specify the correct channel with the "-B" parameter (channel 9 in my case) but obexftp is smart enough to use the correct channel anyway.
Your phone will prompt you to enter the passkey we created earlier (2345), then the phone will ask you to accept "OBEX file transfer, Requested by: BlueZ (0)".
Puppy will then display a list of directories available on your phone in XML format. Let's say one of those directories is "audio". So to list files in this directory, do this -

Code: Select all

obexftp -b 00:17:E3:4B:68:A3 -l /audio
Let's say you see a file called "mymusic.mp3". To get (or "fetch") this file, use the "-g" parameter, like this -

Code: Select all

obexftp -b 00:17:E3:4B:68:A3 -g /audio/mymusic.mp3
Or to send ("put") a file to the phone, use the "-p" parameter.

If the file transfer is initiated from the phone, the process is different ... maybe I will test this some other time.

It may be possible to mount the phone as a filesystem using the obexfs dotpet package from later in this thread, but this will only work with certain phones. Install Obexfs-0.8.pet, then do this -

Code: Select all

mkdir /mnt/bluetooth
obexfs -b 00:17:E3:4B:68:A3 -B 9 /mnt/bluetooth
If it works, you will now be able to browse files in the phone using ROX, or any other file manager.
Last edited by tempestuous on Fri 09 Jul 2010, 10:15, edited 8 times in total.

tempestuous
Posts: 5464
Joined: Fri 10 Jun 2005, 05:12
Location: Australia

#2 Post by tempestuous »

EDIT Feb 21 2008
DBus-1.0.2.pet repackaged to include the necessary directory: /var/run/dbus

Here are the dotpets. All of these packages have been compiled with the correct configuration locations:

/etc/bluetooth/hcid.conf
/etc/bluetooth/rfcomm.conf

/etc/dbus-1/session.conf
/etc/dbus-1/system.conf
/etc/dbus-1/system.d/bluetooth.conf

/var/run/dbus/
/var/lib/dbus/
/var/lib/bluetooth/

BlueZ-utils-3.24 includes the necessary /dev/rfcomm0 device node,
and additional "passkey-agent" utility.
I did not compile bluez-pin, because this requires gconf-2 and orbit2.
Attachments
DBus-GLib-0.74.pet
(69.18 KiB) Downloaded 3887 times
BlueZ-libs-3.24.pet
(31.57 KiB) Downloaded 3262 times
BlueZ-firmware-1.2.pet
(67.02 KiB) Downloaded 3151 times
Last edited by tempestuous on Thu 21 Feb 2008, 09:10, edited 5 times in total.

tempestuous
Posts: 5464
Joined: Fri 10 Jun 2005, 05:12
Location: Australia

#3 Post by tempestuous »

hcidump is optional.
Attachments
BlueZ-hcidump-1.40.pet
(75.13 KiB) Downloaded 2475 times

tempestuous
Posts: 5464
Joined: Fri 10 Jun 2005, 05:12
Location: Australia

#4 Post by tempestuous »

Here is OpenOBEX & ObexFTP, needed to transfer files via bluetooth.

Update Feb 14 2008: ObexFS added. This allows the bluetooth device to be mounted, so files can be browsed like those on any other filesystem.
Note that OpenOBEX still needs to be installed as well.

The official instructions at http://dev.zuckschwerdt.org/openobex/wiki/ObexFs
look complex. Forum member jockjunior explains a more straigtforward mounting process -

Code: Select all

mkdir /mnt/bluetooth  ## this only needs to be done the first time
obexfs -b <phone address> -B <bluetooth channel> /mnt/bluetooth
Now you can access files on the bluetooth device at /mnt/bluetooth
Attachments
Openobex-1.3-apps.pet
(34.45 KiB) Downloaded 2431 times
Obexfs-0.8.pet
(9.47 KiB) Downloaded 2408 times
Obexftp-0.20.pet
(51.91 KiB) Downloaded 2483 times
Last edited by tempestuous on Sat 03 May 2008, 02:03, edited 4 times in total.

tempestuous
Posts: 5464
Joined: Fri 10 Jun 2005, 05:12
Location: Australia

#5 Post by tempestuous »

Here are the Bluetooth-alsa libraries and utilities.
These are for bluetooth headset connections. Of course, the bluez and dbus libraries posted earlier in this thread are also required.
Refer to http://bluetooth-alsa.sourceforge.net/build.html for instructions.
In summary;
For high quality one-way connections in stereo for listening to music,
with either xmms or VLC, use the a2dpd utility.
This package provides the necessary .a2dprc and .asoundrc configuration files in /root

For 2-way connections, the SCO alsa plugin method will probably crash the Puppy kernel,
so you must use the btsco kernel driver method described in the "Legacy drivers" section.
For this, you will need to install the Bluetooth-alsa-btsco package compatible with your Puppy version.
There is a good HOWTO on this technique over at the DamnSmallLinux forum by Juanito -
http://damnsmalllinux.org/cgi-bin/forum ... =bluetooth
Attachments
Bluetooth-alsa-sbc+plugz.pet
(178.72 KiB) Downloaded 2274 times
Bluetooth-alsa-btsco-k2.6.18.1.pet
for Puppy ver 2.12-2.16
(16.03 KiB) Downloaded 1823 times
Bluetooth-alsa-btsco-k2.6.21.7.pet
for Puppy ver 3.x
(17.74 KiB) Downloaded 2009 times

shenen
Posts: 37
Joined: Sun 03 Dec 2006, 18:19

#6 Post by shenen »

When I type scid -n, I got this message:

hcid[16679]: Bluetooth HCI daemon
hcid[16679]: Can't open HCI socket: Address family not supported by protocol (97)

Not sure what went wrong. I have installed those 5 dotpups that you mentioned.

tempestuous
Posts: 5464
Joined: Fri 10 Jun 2005, 05:12
Location: Australia

#7 Post by tempestuous »

Thanks for reporting shenen.
I just tested these commands in a fresh boot to the Puppy 3 CD, and yes, you're right. It's a shame that none of the other 30-or-so people who downloaded these packages reported this problem.

I did some quick testing, and I see that the "rfcomm" module needs to be loaded before the "hcid -n" command will work, so I have just amended the instructions so that the process is performed in a slightly different order. Please try again.

shenen
Posts: 37
Joined: Sun 03 Dec 2006, 18:19

#8 Post by shenen »

tempestuous,
I tested and it went ok. Thanks.

you've contributed a lot to package the applications to make it easy to run so that not every one who uses Linux has to be that technical.

Everytime when I searched what I need, you name shows up all over the places.

Without these easy to install .pet packages, I wouldn't use this distro.

It's me who should thank you.
Thanks,
Shenen

tempestuous
Posts: 5464
Joined: Fri 10 Jun 2005, 05:12
Location: Australia

#9 Post by tempestuous »

Forum member malcom_f reports that for audio support Bluez-utils must be compiled with "--enable-audio".
So I have just recompiled BlueZ-utils-3.24 and re-attached the dotpet above. I used this configuration:

./configure --prefix=/usr --mandir=/usr/share/man --sysconfdir=/etc --localstatedir=/var --libexecdir=/lib --enable-inotify --enable-expat --enable-usb --enable-alsa --enable-obex --enable-glib --enable-audio --enable-input --enable-serial --enable-network --enable-sync --enable-echo --enable-hcid --enable-sdpd --enable-hidd --enable-pand --enable-test --enable-cups --enable-manpages --enable-configfiles --enable-initscripts --enable-pcmciarules --enable-bccmd --enable-avctrl --enable-hid2hci --enable-dfutool --enable-dfubabel

... and I just compiled J-Pilot with bluetooth support, details here -
http://www.murga-linux.com/puppy/viewtopic.php?t=25604

shenen
Posts: 37
Joined: Sun 03 Dec 2006, 18:19

#10 Post by shenen »

I run the same thing again, but it shows something new:

dmesg, it shows:

hci_scodata_packet: hci0 SCO packet for unknown connection handle 92

228 lines of them.

The only difference is that I downloaded the new compiled BlueZ-utils-3.24

and hcid -n shows:

# hcid -n
hcid[4474]: Bluetooth HCI daemon
hcid[4474]: syntax error line 32

not sure what that means.

tempestuous
Posts: 5464
Joined: Fri 10 Jun 2005, 05:12
Location: Australia

#11 Post by tempestuous »

shenen wrote:... dmesg, it shows:
hci_scodata_packet: hci0 SCO packet for unknown connection handle 92
According to this link -
http://www.think-future.de/wiki/index.p ... =Bluetooth
that error message is related to bluetooth audio connections, which is not surprising since the revised version of Bluez-utils now has audio features enabled.
It may be related to the "sco" module, so if you load the sco module, the error message might go away. But I think the error is trivial, anyway.

shenen wrote:hcid[4474]: syntax error line 32
I think this relates to the hcid configuration file /etc/bluetooth/hcid.conf
Line 32 of this file is normally -

Code: Select all

name "BlueZ (%d)";
Did you maybe change this line?

User avatar
Béèm
Posts: 11763
Joined: Wed 22 Nov 2006, 00:47
Location: Brussels IBM Thinkpad R40, 256MB, 20GB, WiFi ipw2100. Frugal Lin'N'Win

#12 Post by Béèm »

tempestuous

Thank you for reviving BT.

This command dbus-uuidgen --ensure when executed says dbus-uuidgen not found.
Is this important?
I can run the dbus daemon however.

I still get somewhat lost in things like hci, rfcomm and tools like hcitool and sdptool.

I followed this thread and could do an upload with the x command.
I didn't find yet to do a download and change the directory location on the phone.

Having with my usb-bt stick a nice gui program I installed it in Wine, but the bt device isn't seen in wine.
Is there something special to do?

I try in alpha 6 and in muppy 008 also.

Also I have a 3.9 pet for bluez utils and libs.
You reference 3.24. Which one should be taken?

EDIT:
When I try to use obexftp the phone ask to add the pc device (as Bluez) and I say yes.
Then an access code is asked. I try to use the one of the phone, but that doesn't match.
Is there a fixed access code in Bluez and which one is it?
Or is there way to set an access code in Bluez?
Time savers:
Find packages in a snap and install using Puppy Package Manager (Menu).
[url=http://puppylinux.org/wikka/HomePage]Consult Wikka[/url]
Use peppyy's [url=http://wellminded.com/puppy/pupsearch.html]puppysearch[/url]

tempestuous
Posts: 5464
Joined: Fri 10 Jun 2005, 05:12
Location: Australia

#13 Post by tempestuous »

Béèm wrote:This command dbus-uuidgen --ensure when executed says dbus-uuidgen not found.
Is this important?
Maybe not so important, but it reveals that you are not using my DBus/Bluetooth dotpets.
All earlier bluetooth packages available on the forum failed to bind to DBus, and then hcid failed to work properly. So it's important to use the versions from this thread.
Béèm wrote:I still get somewhat lost in things like hci, rfcomm and tools like hcitool and sdptool.
Follow the exact order I explained in the first post of this thread.
Béèm wrote:Having with my usb-bt stick a nice gui program I installed it in Wine, but the bt device isn't seen in wine.
Is there something special to do?
I don't know. I imagine that getting hardware devices to work under emulation is difficult. Does Wine use Windows drivers? Or does Wine translate driver commands from Windows into Linux?
Béèm wrote:Also I have a 3.9 pet for bluez utils and libs.
Not possible. As of today Feb 7th 08 the current version is 3.25
http://www.bluez.org/download.html
But whatever version you have, I suggest you change to my packages, because the DBus-Bluetooth linking is critical to success.

Regarding your obexftp questions, I have no experience with this. You should ask giac_fab or JohnDoe.

User avatar
Béèm
Posts: 11763
Joined: Wed 22 Nov 2006, 00:47
Location: Brussels IBM Thinkpad R40, 256MB, 20GB, WiFi ipw2100. Frugal Lin'N'Win

#14 Post by Béèm »

Béèm wrote:
Having with my usb-bt stick a nice gui program I installed it in Wine, but the bt device isn't seen in wine.
Is there something special to do?

I don't know. I imagine that getting hardware devices to work under emulation is difficult. Does Wine use Windows drivers? Or does Wine translate driver commands from Windows into Linux?
I indeed installed the windows drivers that came with the USB stick.
But the USB stick isn't seen by them.

Advice was given, that I should go into the device manager of Wine (like in Windows), but there is no such thing.

However I can go on the internet in Wine without having installed something special, so I suppose the WiFi support of Puppy is used.

I'll continue looking and if I find something, I'll post here.
Time savers:
Find packages in a snap and install using Puppy Package Manager (Menu).
[url=http://puppylinux.org/wikka/HomePage]Consult Wikka[/url]
Use peppyy's [url=http://wellminded.com/puppy/pupsearch.html]puppysearch[/url]

User avatar
Béèm
Posts: 11763
Joined: Wed 22 Nov 2006, 00:47
Location: Brussels IBM Thinkpad R40, 256MB, 20GB, WiFi ipw2100. Frugal Lin'N'Win

#15 Post by Béèm »

Béèm wrote:
Also I have a 3.9 pet for bluez utils and libs.
Tempestuous wrote:
Not possible. As of today Feb 7th 08 the current version is 3.25
Well here is where I got them:
http://www.murga-linux.com/puppy/viewto ... ch&id=3927
and
http://www.murga-linux.com/puppy/viewto ... ch&id=3928

And here is the post I got them from:
http://www.murga-linux.com/puppy/viewto ... 474#115474

But I will uninstall them and install yours as they match maybe better the other stuff.
Time savers:
Find packages in a snap and install using Puppy Package Manager (Menu).
[url=http://puppylinux.org/wikka/HomePage]Consult Wikka[/url]
Use peppyy's [url=http://wellminded.com/puppy/pupsearch.html]puppysearch[/url]

User avatar
Béèm
Posts: 11763
Joined: Wed 22 Nov 2006, 00:47
Location: Brussels IBM Thinkpad R40, 256MB, 20GB, WiFi ipw2100. Frugal Lin'N'Win

#16 Post by Béèm »

OK, back to square one then.
I un-installed the Bluez 3.9 libs and utils.
Rebooted
Installed the 3.24 ones
Rebooted
Now the command:

Code: Select all

# dbus-uuidgen --ensure
# 
is working.
But:

Code: Select all

# dbus-daemon --system
Failed to start message bus: Failed to read directory "/usr/etc/dbus-1/system.d": No such file or directory
So no joy for me to work with Bluetooth, as I understand that the dbus daemon is prerequisite.
Time savers:
Find packages in a snap and install using Puppy Package Manager (Menu).
[url=http://puppylinux.org/wikka/HomePage]Consult Wikka[/url]
Use peppyy's [url=http://wellminded.com/puppy/pupsearch.html]puppysearch[/url]

shenen
Posts: 37
Joined: Sun 03 Dec 2006, 18:19

#17 Post by shenen »

Thanks for the tips tempestuous,
the problem goes away when I restored hcid.conf.

Beem, like you I am also trying to get bluetooth to work, but following the steps prescribed by tempestuous,, I don't have those error message.
Assume it's puppy 3.01.

I also tried x option, and it doesn't work for me, either.

the thing is you don't find too much documentation on how this thing work so you can go after the source, because it is not free.

OBEX (Object Exchange) Protocol:
http://www.irda.org/displaycommon.cfm?a ... ticlenbr=7

I also tried kmobotools:

http://www.kmobiletools.org/node/319
there is a live cd version, and run right out of the box.
However, for me, I can do address book, SMS, but obexftp still doesn't work.

Every time when PC sends the request wants to pair, and I enter the same passcode for both the mobile and PC, it still shows fail to pair.

User avatar
Béèm
Posts: 11763
Joined: Wed 22 Nov 2006, 00:47
Location: Brussels IBM Thinkpad R40, 256MB, 20GB, WiFi ipw2100. Frugal Lin'N'Win

#18 Post by Béèm »

shenen, I am trying in alpha 6.
With the Bluez 3.9 libs and utils, I had more success.
As Tempestuous told me I should use the 3.24 I did so, but now I even can't get the dbus daemon started.
At least with the 3.9 it started.
Don't know quite well what to do next.
Time savers:
Find packages in a snap and install using Puppy Package Manager (Menu).
[url=http://puppylinux.org/wikka/HomePage]Consult Wikka[/url]
Use peppyy's [url=http://wellminded.com/puppy/pupsearch.html]puppysearch[/url]

tempestuous
Posts: 5464
Joined: Fri 10 Jun 2005, 05:12
Location: Australia

#19 Post by tempestuous »

Béèm wrote:

Code: Select all

# dbus-daemon --system
Failed to start message bus: Failed to read directory "/usr/etc/dbus-1/system.d": No such file or directory
Ah, you still have some other version of DBus installed on your system ... maybe the version that came standard with Puppy3/4?

It's VERY IMPORTANT to install all of the dotpets in my 2nd post, not only the Bluetooth dotpets, but also the DBus dotpets.
I was very careful to compile all of these packages with the correct configuration locations.

My version of DBus will definitely reference /etc/dbus-1/system.d which is correct, not /usr/etc/dbus-1/system.d

Regarding obex, and the correct process for copying files from one bluetooth device to another, I have no direct knowledge.
But forum member giac_fab reported success here -
http://www.murga-linux.com/puppy/viewto ... 653#155653
http://www.murga-linux.com/puppy/viewto ... 941#162941

... notice that giac_fab edited his post to say that it only worked under XFCE, that's what made me realise that DBus is so important.
(The XFCE4.4.2 dotpet has its own version of DBus).

So now that the bluetooth and DBus components in my dotpets are playing nicely together, it should be possible (in theory) to reproduce giac_fab's success.
Again, make sure you use my dotpets of Openobex/Obexftp, not some other versions.

User avatar
Béèm
Posts: 11763
Joined: Wed 22 Nov 2006, 00:47
Location: Brussels IBM Thinkpad R40, 256MB, 20GB, WiFi ipw2100. Frugal Lin'N'Win

#20 Post by Béèm »

May I make a remark first.
I don't think it's very logic that a created pet package like dbus-1.0.2.pet has the same sw level, but different sizes.
I don't know if it is made by the same person or two different persons.
But both versions are available in this forum.
It's frustrating, time consuming and creates confusion.
Hope this won't happen again.

Having said that I downloaded again the two dbus pets, the 4 Bluez pets and the two obex pets referenced by Tempestuous.
I un-installed those I had before.
Rebooted
Then installed the 8 pets and rebooted again.

Now comes the truth.

Code: Select all

# dbus-uuidgen --ensure
# dbus-daemon --system
Failed to start message bus: Failed to bind socket "/var/run/dbus/system_bus_socket": No such file or directory
# 
So this is where I stand now.
Still no joy to start the daemon.
In fact I don't have this /var/run/dbus directory.
Time savers:
Find packages in a snap and install using Puppy Package Manager (Menu).
[url=http://puppylinux.org/wikka/HomePage]Consult Wikka[/url]
Use peppyy's [url=http://wellminded.com/puppy/pupsearch.html]puppysearch[/url]

Post Reply