Pairing a client/server from code

1,235 views
Skip to first unread message

Andrew Davison

unread,
Dec 5, 2010, 9:58:02 PM12/5/10
to bluecove-users
I've got two problems related to pairing.

I've written a small client/server application: a client app on a
netbook connects to the
server (running on a PC), sends a string and gets it back converted to
uppercase.

The code works fine with Windows XP SP3, WIDCOMM 5.0.1.1400, and
BlueCove 2.1.0,
but I need to pair the client and server manually. This means entering
a passkey
on both devices before the client can contact the server.

I want to change that to carry out the pairing inside the programs.
That's
where my problems begin :)

On the client-side, I added a call to
RemoteDeviceHelper.authenticate(), like so:

// get a URL for the service
String servURL = servRecord.getConnectionURL(
ServiceRecord.NOAUTHENTICATE_NOENCRYPT,
false);
if (servURL == null)
return;

try {
RemoteDevice dev = servRecord.getHostDevice();
boolean authRes = RemoteDeviceHelper.authenticate(dev,
PASS_KEY);
:

This causes a dialog box to appear on the server side, asking the
server to accept the
passkey. However, after less than a second the authenticate() call
raises a
"Bonding Error [4]" and fails. This occurs so quickly that I don't
have time to accept
the passkey on the server side. How can I fix that?

A more fundamental problem is that I want to carry out the server-side
of the pairing
with code as well. How can I augment code like the following:

StreamConnectionNotifier server =
(StreamConnectionNotifier) Connector.open(
"btspp://localhost:" + UUID_STRING + ";name=" +
SERVICE_NAME +
";authenticate=false");
while (true) {
System.out.println("Waiting for incoming connection...");
StreamConnection conn = server.acceptAndOpen();
processClient(conn);
}

I don't see how to access the client's device without calling
acceptAndOpen(), which
won't succeed unless a pairing has already taken place.

- Andrew

Neal Peacock

unread,
Dec 6, 2010, 2:21:08 PM12/6/10
to bluecov...@googlegroups.com
I haven't tried pairing in windows but since I haven't seen a response for
you yet I thought I would offer what works for me in Linux. If you build
bluez with --enable-tools (I think) it will create an 'agent' program that
is their simple agent. When run it (I start it up from my java code) it
will accept all pairing request and I think would solve your problem if
running on the server side. I'm not sure if Linux is an option for you but
we had similar requirements and this is how we got around manual pairing.

- Andrew

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


Andrew Davison

unread,
Dec 6, 2010, 10:50:54 PM12/6/10
to bluecove-users

Neal,

Thanks for the pointer, but I'd like to stick with Windows if
possible.

It looks like a Windows passkey agent has been requested before -- see
bluecove issue 71 at
http://code.google.com/p/bluecove/issues/detail?id=71 (Such an agent
would
require the use of BluetoothRegisterForAuthentication). Even if there
was a Windows agent,
would it work with the WIDCOMM stack?

To evereyone: as a fallback, is there a way to create a bluetooth
server on WIDCOMM which doesn't require
a passkey?





Andrew Davison

unread,
Dec 8, 2010, 4:43:46 AM12/8/10
to bluecove-users
I've found one "solution" for making a server automatically pair with
a connecting client. Each client can be configured via WIDCOMM's "My
Bluetooth Places" interface. Start its "Bluetooth setup wizard", and
select the 2nd of the 4 options, which says "I want to find a specific
Bluetooth device and configure how this computer will use its
services". Select the device running your server. On the "Bluetooth
Pairing" screen, press the "Skip" button to specify that the server's
device doesn't need a passkey for this client.

This will mean that there's no need to include any pairing code in
this client, and no pairing dialog boxes appear on either devices at
run time.

The drawback is that you will need to do this configuration in every
client that's going to use the server.
Reply all
Reply to author
Forward
0 new messages