bluetooth rfcomm socket to linux/bluez pc?

2,252 views
Skip to first unread message

bsd_mike

unread,
Oct 5, 2010, 8:14:01 AM10/5/10
to android-platform
Hello,
I am trying to get a bluetooth android client connecting to a bluez
linux bluetooth server.
The client code I found here:
http://www.anddev.org/networking-database-problems-f29/bluetooth-threading-or-interrupt-t16496.html

The server code I found here:
http://code.google.com/p/pybluez/source/browse/trunk/examples/simple/rfcomm-server.py

I have installed all the bluez code it seems I need, but I can't seem
to get the socket
connection between the two devices.

I do have the UUID the same on both devices.

On the bluez pc side, is there anything I have to do or manually
start?
It seems it may have something to do with channels...or sdp...or
something, but I am a bit lost.

I see no activity at all in the hci dump.

I can do a l2ping between the pc and the android.

I can 'pair' the devices.

I just can't open a socket...

Any help would be appreciated.

-Mike

Leandro de Oliveira

unread,
Oct 5, 2010, 9:37:46 AM10/5/10
to android-...@googlegroups.com
I have the same issue trying to connect to my ubuntu pc with a nexus
one running froyo.
Android -> Windows works perfectly, Android -> Linux does not.

2010/10/5 bsd_mike <bsdd...@gmail.com>:

> --
> You received this message because you are subscribed to the Google Groups "android-platform" group.
> To post to this group, send email to android-...@googlegroups.com.
> To unsubscribe from this group, send email to android-platfo...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/android-platform?hl=en.
>
>

bsd_mike

unread,
Oct 5, 2010, 10:12:21 AM10/5/10
to android-platform

How are you testing bluetooth sockets on Windows?
Is there some opensource software?
-Mike

On Oct 5, 8:37 am, Leandro de Oliveira <lehph...@gmail.com> wrote:
> I have the same issue trying to connect to my ubuntu pc with a nexus
> one running froyo.
> Android -> Windows works perfectly, Android -> Linux does not.
>
> 2010/10/5 bsd_mike <bsddo...@gmail.com>:
>
>
>
> > Hello,
> > I am trying to get a bluetooth android client connecting to a bluez
> > linux bluetooth server.
> > The client code I found here:
> >http://www.anddev.org/networking-database-problems-f29/bluetooth-thre...
>
> > The server code I found here:
> >http://code.google.com/p/pybluez/source/browse/trunk/examples/simple/...

Leandro de Oliveira

unread,
Oct 5, 2010, 10:38:40 AM10/5/10
to android-...@googlegroups.com
I'm using bluecove (http://bluecove.org) which calls the microsoft
bluetooth stack on Windows and bluez on Linux.

2010/10/5 bsd_mike <bsdd...@gmail.com>:

jaikumar Ganesh

unread,
Oct 5, 2010, 1:07:12 PM10/5/10
to android-...@googlegroups.com
Which Bluez version are you using on the Linux box and which phone are u using ?
Are you using secureRfcomm API ?

bsd_mike

unread,
Oct 5, 2010, 1:46:43 PM10/5/10
to android-platform
Bluez 4.60
PyBluez 0.15
Bluez-utils 3.36

I was running on a EVO, but am moving to a motorola droid when I test
again.
I was not intending to use the secure RFcomm API.

Thanks,
Mike

On Oct 5, 12:07 pm, jaikumar Ganesh <jaikum...@gmail.com> wrote:
> Which Bluez version are you using on the Linux box and which phone are u using ?
> Are you using secureRfcomm API ?
>
> On Tue, Oct 5, 2010 at 4:38 PM, Leandro de Oliveira <lehph...@gmail.com> wrote:
>
>
>
> > I'm using bluecove (http://bluecove.org) which calls the microsoft
> > bluetooth stack on Windows and bluez on Linux.
>
> > 2010/10/5 bsd_mike <bsddo...@gmail.com>:

Leandro de Oliveira

unread,
Oct 5, 2010, 3:42:14 PM10/5/10
to android-...@googlegroups.com
I'd like to point out that I get one or two successful connections and
then nothing.
I'm using Bluez 4.

The android code is here:
http://code.google.com/p/android-notifier/source/browse/trunk/AndroidNotifier/src/org/damazio/notifier/notification/BluetoothNotificationMethod.java
And the server code is here:
http://code.google.com/p/android-notifier/source/browse/trunk/MultiDroidNotifier/src/main/java/com/notifier/desktop/notification/bluetooth/BluetoothNotificationReceiver.java

I see these messages in android:

E/BluetoothEventLoop.cpp( 86): event_filter: Received signal
org.bluez.Device:PropertyChanged from
/org/bluez/14139/hci0/dev_07_D3_00_71_2D_10
D/BluetoothService( 86): 07:D3:00:71:2D:10 bond state 11 -> 12 (0)
V/BluetoothEventRedirector(13338): Received
android.bluetooth.device.action.BOND_STATE_CHANGED
E/BluetoothService.cpp( 86): stopDiscoveryNative: D-Bus error in
StopDiscovery: org.bluez.Error.Failed (Invalid discovery session)

And the android client prints the following, which means no
IOException is thrown even though no message is sent to the server:

D/RemoteNotifier(14018): Sent notification over Bluetooth (0 retries).

Thank you

2010/10/5 bsd_mike <bsdd...@gmail.com>:

jaikumar Ganesh

unread,
Oct 5, 2010, 4:57:39 PM10/5/10
to android-...@googlegroups.com
bsd_mike: EVO uses a Broadcomm stack not the stock Android stack.
Please test with Motorola droid or a Nexus One.

Leandro: On the client side (Android) you are creating a MITM socket
with encyrption enabled.
What kind of socket is created on the server side ? notifier.acceptAndOpen code.

Is the Bluez agent registered with DisplayYesNo on the PC side ?

Leandro de Oliveira

unread,
Oct 5, 2010, 5:20:51 PM10/5/10
to android-...@googlegroups.com
> What kind of socket is created on the server side ?
My RFCOMM url is
btspp://localhost:7674047e6e474bf0831f209e3f9dd23f;name=AndroidNotifierService;authenticate=true;encrypt=true
which enables authentication and encryption according to JSR-82.

> Is the Bluez agent registered with DisplayYesNo on the PC side ?

I don't know how to see if this is registered. If you want to know if
the Nexus One is paired with the PC, yes it is.

2010/10/5 jaikumar Ganesh <jaik...@gmail.com>:

jaikumar Ganesh

unread,
Oct 5, 2010, 6:02:28 PM10/5/10
to android-...@googlegroups.com
On Tue, Oct 5, 2010 at 11:20 PM, Leandro de Oliveira <lehp...@gmail.com> wrote:
>> What kind of socket is created on the server side ?
> My RFCOMM url is
> btspp://localhost:7674047e6e474bf0831f209e3f9dd23f;name=AndroidNotifierService;authenticate=true;encrypt=true
> which enables authentication and encryption according to JSR-82.
>
>> Is the Bluez agent registered with DisplayYesNo on the PC side ?
> I don't know how to see if this is registered. If you want to know if
> the Nexus One is paired with the PC, yes it is.

Ok when you paired, did you get a passkey dialog displayed on both
Android and PC to compare the passkey or did it just pair
automatically ?
Also which bluez version is being used on the PC ?

Leandro de Oliveira

unread,
Oct 5, 2010, 6:24:59 PM10/5/10
to android-...@googlegroups.com
Yes, it did show a dialog and I entered the same passkey in both.
I'm using Bluez 4 which is detected by bluecove.

This is the output of apt-cache policy bluez:

Installed: 4.69-0ubuntu2
Candidate: 4.69-0ubuntu2

And this one of apt-cache policy libbluetooth-dev:

Installed: 4.69-0ubuntu2
Candidate: 4.69-0ubuntu2

I have these files in /usr/lib:

libbluetooth.la
libbluetooth.so -> libbluetooth.so.3.9.0
libbluetooth.so.3 -> libbluetooth.so.3.9.0
libbluetooth.so.3.9.0

Bluecove loads libbluetooth.so as documented in this link:
http://bluecove.org/bluecove-gpl/

You should be able to reproduce this installing libbluetooth-dev
package on Ubuntu and running these classes I posted before using a
Nexus One running non-rooted Froyo 2.2.1.

2010/10/5 jaikumar Ganesh <jaik...@gmail.com>:

bsd_mike

unread,
Oct 5, 2010, 9:05:21 PM10/5/10
to android-platform


On Oct 5, 3:57 pm, jaikumar Ganesh <jaikum...@gmail.com> wrote:
> bsd_mike: EVO uses a Broadcomm stack not the stock Android stack.

I'll be darned...Worked perfectly with no code change at all!!

Thanks, wonder what one has to do to get the evo to work...not that I
need to now.

Mike

jaikumar Ganesh

unread,
Oct 6, 2010, 4:20:43 AM10/6/10
to android-...@googlegroups.com
bsd_mike: HTC is aware of the problem and I believe its already fixed
but I guess you have not received the OTAed. I have asked HTC to reply
to this thread.

Leandro: Ah, I guess your PC is Bluetooth 2.0. Can you provide with
hcidump on both sides and a logcat on the android side ?

Thanks

Leandro de Oliveira

unread,
Oct 6, 2010, 10:45:26 AM10/6/10
to android-...@googlegroups.com
The logcat output is: http://dl.dropbox.com/u/1401233/logcat.txt
Here is the hcidump from the PC: http://dl.dropbox.com/u/1401233/pc-hcidump.txt
I tried to run hcidump using adb but I got "hcidump: permission
denied", I guess I need a rooted phone to get it, I don't have one,
sorry.

2010/10/6 jaikumar Ganesh <jaik...@gmail.com>:

Leandro de Oliveira

unread,
Oct 6, 2010, 10:52:25 AM10/6/10
to android-...@googlegroups.com
And here is the log output of bluecove:

DEBUG [bluetooth] - open using BlueCove javax.microedition.io.Connector
DEBUG [bluetooth] - connecting


btspp://localhost:7674047e6e474bf0831f209e3f9dd23f;name=AndroidNotifierService;authenticate=true;encrypt=true

DEBUG [bluetooth] - RFCOMM set authenticate
DEBUG [bluetooth] - created SDPSession 30213872
DEBUG [bluetooth] - BlueZ major verion 4 detected
DEBUG [bluetooth] - function sdp_extract_pdu of bluez major version 4 is called
DEBUG [bluetooth] - pdu scanned 79 -> 79

This is the log output when a message is successfully received by the
desktop app:

DEBUG [bluetooth] - RFCOMM client accepted, handle 38
DEBUG [bluetooth] - new RemoteDevice 0023769EC65D
DEBUG [bluetooth] - new devicesCashed 0x23769ec65d
DEBUG [bluetooth] - connection open, open now 1
DEBUG [bluetooth] - Connection closed, Connection reset by peer
INFO [NotificationManagerImpl] - Notification received:
notificationId=38608649427977616, type=SMS <-- Here is the message
content I got
DEBUG [bluetooth] - closing RFCOMM Connection 38
DEBUG [bluetooth] - connection closed, open now 0
DEBUG [bluetooth] - RFCOMM disconnect, handle 38

I get two successful connections and then no log at all for new
messages, but hcidump says something is happening.

2010/10/6 Leandro de Oliveira <lehp...@gmail.com>:

Leandro de Oliveira

unread,
Oct 8, 2010, 11:24:59 AM10/8/10
to android-...@googlegroups.com
> HTC is aware of the problem and I believe its already fixed but I guess you have not received the OTAed.
We've had dozens of reports about bluetooth issues in HTC devices.
Some devices open the connection but send 0 bytes, some don't and some
send all data successfully at random intervals. A large number of
people are Mac and Linux users, very few Windows users have this kind
of problem (2 or 3 maybe).

I'm trying to keep all bluetooth related discussion in this page if
you want to take a look:
http://code.google.com/p/android-notifier/issues/detail?id=3

jaikumar Ganesh

unread,
Nov 11, 2010, 7:49:05 PM11/11/10
to Leandro de Oliveira, android-...@googlegroups.com
Sorry for taking time to get back to this.

I tried opening an rfcomm socket from a  linux box running Bluez4 and an Android phone running Froyo using the Bluez tools and I didn't see any problem.

Since you can't get hcidump on the device, do you have a Bluetooth sniffer to provide a sniff log for me to see why rfcomm is getting disconnected ?

Thanks
Reply all
Reply to author
Forward
0 new messages