Author Topic: Secure bluetooth chat server and client  (Read 19475 times)

TonyJuurlink

  • Guest
Secure bluetooth chat server and client
« on: December 12, 2013, 04:29:48 AM »
I am looking to build something like the demo BlueChat server and client, with Authentication.  Client and Server will run on Windows 7, MS Stack, and should support Bluetooth 2.0, 2.1, and 4.0.  I do not want the users to manually pair, but rather have that handled by the client/server apps.

I have altered the BlueChatServer by adding the wclAuthenticator, and change BlueChatClient to use Authentication.  I have attached the "Main" form code..

When I run using machines with Bluetooth 2.0, the apps connect and communicate.  When I run using machines with Bluetooth 2.1, I get Connection error :45.

Do I need to also use wclAuthenticator on the client application, or is there something else I am missing.  Any help would be appreciated.

Thanks.

[attachment deleted by admin]

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3675
  • Karma: 1000
    • Wireless Communication Libraries
Re: Secure bluetooth chat server and client
« Reply #1 on: December 12, 2013, 09:13:42 AM »
Hello,

Yes you have to use wclAuthenticator on both sides.

TonyJuurlink

  • Guest
Re: Secure bluetooth chat server and client
« Reply #2 on: December 12, 2013, 02:50:25 PM »
Thanks for your response. 

I have setup the wclAuthenticator on the client (client main form code snip below), and am still getting the Error 45 when trying to use on Bluetooth 2.1 devices.  2.0 works fine.

Code: [Select]
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace BlueChatClient
{
    public partial class fmMain : Form
    {
        private wcl.wclAPI wclAPI;
        private wcl.wclBluetoothDiscovery wclBluetoothDiscovery;
        private wcl.wclClient wclClient;
        private wcl.wclAuthenticator wclAuthenticator;
       
        public fmMain()
        {
            InitializeComponent();

            wclAPI = new wcl.wclAPI();

            wclBluetoothDiscovery = new wcl.wclBluetoothDiscovery();
            wclBluetoothDiscovery.OnDiscoveryStarted += new wcl.wclBluetoothDiscoveryStartedEventHandler(wclBluetoothDiscovery_OnDiscoveryStarted);
            wclBluetoothDiscovery.OnDiscoveryComplete += new wcl.wclBluetoothDiscoveryCompleteEventHandler(wclBluetoothDiscovery_OnDiscoveryComplete);

            wclClient = new wcl.wclClient();
            wclClient.OnDisconnect += new System.EventHandler(wclClient_OnDisconnect);
            wclClient.OnData += new wcl.wclDataEventHandler(wclClient_OnData);
            wclClient.OnConnect += new wcl.wclConnectEventHandler(wclClient_OnConnect);


            wclAuthenticator = new wcl.wclAuthenticator();
            wclAuthenticator.OnNumericComparison += new wcl.wclNumericComparisonEventHandler(wclAuthenticator_OnNumericComparison);
            wclAuthenticator.OnPasskey += new wcl.wclPasskeyEventHandler(wclAuthenticator_OnPasskey);
            wclAuthenticator.OnPINRequest += new wcl.wclPINRequestEventHandler(wclAuthenticator_OnPINRequest);

            wclAuthenticator.OnPaired += new wcl.wclPairedEventHandler(wclAuthenticator_OnPaired);
            wclAuthenticator.OnPasskeyNotification += new wcl.wclPasskeyNotificationEventHandler(wclAuthenticator_OnPasskeyNotification);

        }

        private void fmMain_Load(object sender, EventArgs e)
        {
            wclAPI.Load();
        }

        private void fmMain_FormClosed(object sender, FormClosedEventArgs e)
        {
            wclAPI.Unload();

            wclClient.Dispose();
            wclBluetoothDiscovery.Dispose();
            wclAPI.Dispose();
        }

        private wcl.wclBluetoothRadio GetSelectedRadio()
        {
            wcl.wclBluetoothRadio Radio = null;
            wcl.wclBluetoothRadios Radios = new wcl.wclBluetoothRadios();
            if (wclBluetoothDiscovery.EnumRadios(Radios) == wcl.wclErrors.WCL_E_SUCCESS && Radios.Count > 0)
            {
                Radio = new wcl.wclBluetoothRadio();
                Radio.Assign(Radios[0]);
            }
            if (Radio == null)
                MessageBox.Show("No Bluetooth API was found.");
            return Radio;
        }

        private void btDiscover_Click(object sender, EventArgs e)
        {
            wcl.wclBluetoothRadio Radio = GetSelectedRadio();
            if (Radio != null)
            {
                wcl.wclErrors.wclShowError(wclBluetoothDiscovery.Discovery(Radio));
            }
        }

        private void wclBluetoothDiscovery_OnDiscoveryStarted(object sender, wcl.wclBluetoothDiscoveryStartedEventArgs e)
        {
            lvDevices.Items.Clear();
            MessageBox.Show("Started");
        }

        private void wclBluetoothDiscovery_OnDiscoveryComplete(object sender, wcl.wclBluetoothDiscoveryCompleteEventArgs e)
        {
            if (e.Devices == null)
                MessageBox.Show("Error discovering");
            else
                if (e.Devices.Count == 0)
                    MessageBox.Show("Nothing found");
                else
                    for (uint i = 0; i < e.Devices.Count; i++)
                    {
                        wcl.wclBluetoothDevice Device = e.Devices[i];
                        ListViewItem Item = lvDevices.Items.Add(Device.Address);
                        string str = "";
                        Device.GetName(e.Radio, ref str);
                        Item.SubItems.Add(str);
                    }
        }

        private void btConnect_Click(object sender, EventArgs e)
        {
            wcl.wclBluetoothRadio Radio = GetSelectedRadio();
            if (Radio != null)
            {
                if (lvDevices.SelectedItems.Count == 0)
                    MessageBox.Show("Selected device");
                else
                {
                    string Address = lvDevices.SelectedItems[0].Text;

                    wclAuthenticator.Radio = Radio;
                    int Res = wclAuthenticator.Open();
                    if (Res != wcl.wclErrors.WCL_E_SUCCESS)
                    {
                        MessageBox.Show("Unable open Authenticator: " + wcl.wclErrors.wclGetErrorMessage(Res));
                        Radio = null;
                    }

                    wclClient.BluetoothParams.Address = Address;
                    wclClient.BluetoothParams.Radio = Radio;
                    wclClient.BluetoothParams.Service = new Guid("{71D47FA1-87B6-4629-AB78-77B482AE5316}");
                    wclClient.BluetoothParams.Authentication = true;
                    wclClient.BluetoothParams.Encryption = false;
                    wclClient.Transport = wcl.wclTransport.trBluetooth;
                    wcl.wclErrors.wclShowError(wclClient.Connect());
                }
            }
        }

        private void wclClient_OnConnect(object sender, wcl.wclConnectEventArgs e)
        {
            if (e.Error != wcl.wclErrors.WCL_E_SUCCESS)
                MessageBox.Show("Unable connect: " + e.Error.ToString());
            else
                MessageBox.Show("Connected");
        }

        private void btDisconnect_Click(object sender, EventArgs e)
        {
            wclClient.Disconnect();
        }

        private void wclClient_OnDisconnect(object sender, EventArgs e)
        {
            MessageBox.Show("Disconnected");
        }

        private void btSend_Click(object sender, EventArgs e)
        {
            string str = edCmd.Text;

            Encoding Coder = Encoding.ASCII;
            byte[] Buf = Coder.GetBytes(str);

            wcl.wclErrors.wclShowError(wclClient.Write(Buf, (uint)str.Length));
        }

        private void wclClient_OnData(object sender, wcl.wclDataEventArgs e)
        {
            Encoding Coder = Encoding.ASCII;
            string str = Coder.GetString(e.Data);

            edAns.Text = edAns.Text + "/r" + str;
        }
        private void wclAuthenticator_OnPINRequest(object sender, wcl.wclPINRequestEventArgs e)
        {
            e.PIN = "1234";
        }

        void wclAuthenticator_OnPasskey(object sender, wcl.wclNumericComparisonEventArgs e)
        {
            e.Confirm = true;
        }

        void wclAuthenticator_OnNumericComparison(object sender, wcl.wclNumericComparisonEventArgs e)
        {
            e.Confirm = true;
        }
        void wclAuthenticator_OnPaired(object sender, wcl.wclPairedEventArgs e)
        {
            if (!wcl.wclErrors.wclShowError(e.Error))
                MessageBox.Show("Paired");
        }

        void wclAuthenticator_OnPasskeyNotification(object sender, wcl.wclPasskeyEventArgs e)
        {
            MessageBox.Show(String.Format("Passkey notification: %06u", e.Value));
        }
    }
}

The wclAuthenticator_On* events do not fire on the server or client.  Is there something else I need to do to kick off the authentication?  My understanding was that I should not need to pair if using the wclAuthenticator.

Thanks

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3675
  • Karma: 1000
    • Wireless Communication Libraries
Re: Secure bluetooth chat server and client
« Reply #3 on: December 12, 2013, 03:48:02 PM »
Which OS and BT stacks on both sides?

TonyJuurlink

  • Guest
Re: Secure bluetooth chat server and client
« Reply #4 on: December 12, 2013, 03:52:00 PM »
Windows 7
Microsoft stack - driver version 6.1.7601.17889

Thanks 

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3675
  • Karma: 1000
    • Wireless Communication Libraries
Re: Secure bluetooth chat server and client
« Reply #5 on: December 12, 2013, 03:55:42 PM »
Thank you. I'll try to reproduce and back to you.

TonyJuurlink

  • Guest
Re: Secure bluetooth chat server and client
« Reply #6 on: December 12, 2013, 04:01:54 PM »
Thanks very much.  The server code is attached in the initial message.

TonyJuurlink

  • Guest
Re: Secure bluetooth chat server and client
« Reply #7 on: December 13, 2013, 04:12:54 PM »
Hey Mike, any luck with that?
Thanks,
Tony

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3675
  • Karma: 1000
    • Wireless Communication Libraries
Re: Secure bluetooth chat server and client
« Reply #8 on: December 13, 2013, 04:23:18 PM »
Hi,

Checking. It looks we were able to reproduce the issue now trying to find what's going wrong as it appears no always. I'll be in touch.

TonyJuurlink

  • Guest
Re: Secure bluetooth chat server and client
« Reply #9 on: December 13, 2013, 06:28:41 PM »
Thanks Mike.  Your rapid response times are very much appreciated.

TonyJuurlink

  • Guest
Re: Secure bluetooth chat server and client
« Reply #10 on: December 16, 2013, 02:52:20 PM »
Hello Mike,
Any progress?  I failed to mention that we are using wcl version 6.12.6.0.  Do you think it would be worth us trying to revert to an earlier version?
Thanks

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3675
  • Karma: 1000
    • Wireless Communication Libraries
Re: Secure bluetooth chat server and client
« Reply #11 on: December 16, 2013, 04:17:24 PM »
Hello,

It is not related to WCL version. It is something regarding how MS driver executes authentication. I think I'll be ready to provide you with more useful information in about 2-3 days.

TonyJuurlink

  • Guest
Re: Secure bluetooth chat server and client
« Reply #12 on: December 16, 2013, 04:41:53 PM »
Thanks Mike.

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3675
  • Karma: 1000
    • Wireless Communication Libraries
Re: Secure bluetooth chat server and client
« Reply #13 on: December 18, 2013, 04:46:36 PM »
Hello,

FYI we finished checking this issue and it appears like on some systems MS driver doesn't handle authentication requests for server. We will continue working on this matter to try to find a workaround.

TonyJuurlink

  • Guest
Re: Secure bluetooth chat server and client
« Reply #14 on: December 18, 2013, 06:30:28 PM »
Thanks Mike.

I have found that the following code works for me across various devices/bt versions:

Server:
Code: [Select]
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace BlueChatServer
{
    public partial class fmMain : Form
    {
        private wcl.wclAPI wclAPI;
        private wcl.wclBluetoothDiscovery wclBluetoothDiscovery;
        private wcl.wclServer wclServer;
        private wcl.wclAuthenticator wclAuthenticator;
        private wcl.wclBluetoothRadio Radio = null;

        private bool SelectRadio()
        {
            bool Result = false;
            wcl.wclBluetoothRadios Radios = new wcl.wclBluetoothRadios();
            int Res = wclBluetoothDiscovery.EnumRadios(Radios);
            if (Res != wcl.wclErrors.WCL_E_SUCCESS)
            {
                //lbLog.Items.Add("Enum radios error: " + wcl.wclErrors.wclGetErrorMessage(Res));
                if (Radio != null)
                {
                    Radio = null;
                    Result = true;
                }
            }
            else
            {
                if (Radios.Count == 0)
                {
                    //lbLog.Items.Add("No radios were found");
                    if (Radio != null)
                    {
                        Radio = null;
                        Result = true;
                    }
                }
                else
                    if (Radio != null)
                    {
                        if (Radios[0].API != Radio.API)
                        {
                            Result = true;
                            Radio.Assign(Radios[0]);
                        }
                    }
                    else
                    {
                        Result = true;
                        Radio = new wcl.wclBluetoothRadio();
                        Radio.Assign(Radios[0]);
                    }
            }
            Radios = null;

            return Result;
        }

        public fmMain()
        {
            InitializeComponent();

            wclAPI = new wcl.wclAPI();
            wclAPI.AfterLoad += new System.EventHandler(wclAPI_AfterLoad);
            wclAPI.OnChanged += new System.EventHandler(wclAPI_OnChanged);
            wclAPI.AfterUnload += new System.EventHandler(wclAPI_AfterUnload);


            wclBluetoothDiscovery = new wcl.wclBluetoothDiscovery();
           
            wclServer = new wcl.wclServer();
            wclServer.OnClosed += new System.EventHandler(wclServer_OnClosed);
            wclServer.OnData += new wcl.wclDataEventHandler(wclServer_OnData);
            wclServer.OnDisconnected += new System.EventHandler(wclServer_OnDisconnected);
            wclServer.OnConnected += new System.EventHandler(wclServer_OnConnected);
            wclServer.OnListen += new wcl.wclConnectEventHandler(wclServer_OnListen);

            wclAuthenticator = new wcl.wclAuthenticator();
            wclAuthenticator.OnNumericComparison += new wcl.wclNumericComparisonEventHandler(wclAuthenticator_OnNumericComparison);
            wclAuthenticator.OnPasskey += new wcl.wclPasskeyEventHandler(wclAuthenticator_OnPasskey);
            wclAuthenticator.OnPINRequest += new wcl.wclPINRequestEventHandler(wclAuthenticator_OnPINRequest);
        }
       
        private void StartListener()
        {
            if (wclServer.State != wcl.wclServerState.ssClosed)
                MessageBox.Show("Server is active");
            else
            {
                if (Radio != null)
                {
                    wclAuthenticator.Radio = Radio;
                    int Res = wclAuthenticator.Open();
                    if (Res != wcl.wclErrors.WCL_E_SUCCESS)
                    {
                        //lbLog.Items.Add("Unable open Authenticator: " + wcl.wclErrors.wclGetErrorMessage(Res));
                        Radio = null;
                    }
                    else
                    {
                        //lbLog.Items.Add("Authenticator has been opened");
                        wclServer.Transport = wcl.wclTransport.trBluetooth;
                        wclServer.BluetoothParams.Radio = Radio;
                        wclServer.BluetoothParams.Authentication = true;
                        wclServer.BluetoothParams.Encryption = true;
                        wclServer.BluetoothParams.Service = new Guid("{71D47FA1-87B6-4629-AB78-77B482AE5316}");
                        wcl.wclErrors.wclShowError(wclServer.Listen());
                    }
                }
            }
        }

        private void StopListener()
        {
            if (wclAuthenticator.Active == true)
            {
                wclAuthenticator.Close();
            }
            wclAuthenticator.Radio = null;
            if (wclServer.State != wcl.wclServerState.ssClosed)
            {
                wclServer.Close();
            }
        }

        private void fmMain_Load(object sender, EventArgs e)
        {
            wclServer.BluetoothParams.Authentication = true;
            wclServer.BluetoothParams.Name = "WCL OPP Server";

            wclAPI.Load();
        }

        private void fmMain_FormClosed(object sender, FormClosedEventArgs e)
        {
            StopListener();
            wclAPI.Unload();

            wclAuthenticator.Dispose();
            wclServer.Dispose();
            wclBluetoothDiscovery.Dispose();
            wclAPI.Dispose();
            Radio.Dispose();
        }


        private void wclAPI_AfterLoad(object sender, EventArgs e)
        {
            SelectRadio();
            StartListener();
        }

        private void wclAPI_AfterUnload(object sender, EventArgs e)
        {
            MessageBox.Show("wclAPI_AfterUnload");
        }

        private void wclAPI_OnChanged(object sender, EventArgs e)
        {
            MessageBox.Show("wclAPI_OnChanged");
        }

        void wclAuthenticator_OnPasskey(object sender, wcl.wclNumericComparisonEventArgs e)
        {
            e.Confirm = true;
        }

        void wclAuthenticator_OnNumericComparison(object sender, wcl.wclNumericComparisonEventArgs e)
        {
            e.Confirm = true;
        }



        private void wclServer_OnClosed(object sender, EventArgs e)
        {
            listBox.Items.Add("Closed");
        }

        private void wclServer_OnConnected(object sender, EventArgs e)
        {
            listBox.Items.Add("Connected: " + wclServer.Address + " " + wclServer.DeviceName);
        }

        private void wclServer_OnDisconnected(object sender, EventArgs e)
        {
            listBox.Items.Add("Disconnected " + wclServer.Address + " " + wclServer.DeviceName);
        }
       
        private void wclServer_OnListen(object sender, wcl.wclConnectEventArgs e)
        {
            listBox.Items.Add("Listen: " + e.Error.ToString());
        }

        private void btSend_Click(object sender, EventArgs e)
        {
            string str = edCmd.Text;

            Encoding Coder = Encoding.ASCII;
            byte[] Buf = Coder.GetBytes(str);

            wcl.wclErrors.wclShowError(wclServer.Write(Buf, (uint)str.Length));
        }

        private void wclServer_OnData(object sender, wcl.wclDataEventArgs e)
        {
            Encoding Coder = Encoding.ASCII;
            string str = Coder.GetString(e.Data);

            listBox.Items.Add(str);
        }
        private void wclAuthenticator_OnPINRequest(object sender, wcl.wclPINRequestEventArgs e)
        {
            //lbLog.Items.Add("Device " + e.Device.Address + " requires authentication");
            //if (edPIN.Text == "")
            //    edPIN.Text = "0000";
            e.PIN = "0000";
        }
    }
}

Client:
Code: [Select]
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace BlueChatClient
{
    public partial class fmMain : Form
    {
        private wcl.wclAPI wclAPI;
        //private wcl.wclAuthenticator wclAuthenticator;
        private wcl.wclBluetoothDiscovery wclBluetoothDiscovery;
        private wcl.wclClient wclClient;
        private wcl.wclBluetoothRadio Radio = null;


        private bool SelectRadio()
        {
            bool Result = false;
            wcl.wclBluetoothRadios Radios = new wcl.wclBluetoothRadios();
            int Res = wclBluetoothDiscovery.EnumRadios(Radios);
            if (Res != wcl.wclErrors.WCL_E_SUCCESS)
            {
                //lbLog.Items.Add("Enum radios error: " + wcl.wclErrors.wclGetErrorMessage(Res));
                if (Radio != null)
                {
                    Radio = null;
                    Result = true;
                }
            }
            else
            {
                if (Radios.Count == 0)
                {
                    //lbLog.Items.Add("No radios were found");
                    if (Radio != null)
                    {
                        Radio = null;
                        Result = true;
                    }
                }
                else
                    if (Radio != null)
                    {
                        if (Radios[0].API != Radio.API)
                        {
                            Result = true;
                            Radio.Assign(Radios[0]);
                        }
                    }
                    else
                    {
                        Result = true;
                        Radio = new wcl.wclBluetoothRadio();
                        Radio.Assign(Radios[0]);
                    }
            }
            Radios = null;

            return Result;
        }

        public fmMain()
        {
            InitializeComponent();

            wclAPI = new wcl.wclAPI();

            wclAPI.AfterLoad += new System.EventHandler(wclAPI_AfterLoad);
            wclAPI.OnChanged += new System.EventHandler(wclAPI_OnChanged);
            wclAPI.AfterUnload += new System.EventHandler(wclAPI_AfterUnload);

            //wclAuthenticator = new wcl.wclAuthenticator();
            //wclAuthenticator.OnPINRequest += new wcl.wclPINRequestEventHandler(wclAuthenticator_OnPINRequest);
            //wclAuthenticator.OnNumericComparison += new wcl.wclNumericComparisonEventHandler(wclAuthenticator_OnNumericComparison);
            //wclAuthenticator.OnPasskey += new wcl.wclPasskeyEventHandler(wclAuthenticator_OnPasskey);
           
            wclBluetoothDiscovery = new wcl.wclBluetoothDiscovery();
            wclBluetoothDiscovery.OnDiscoveryStarted += new wcl.wclBluetoothDiscoveryStartedEventHandler(wclBluetoothDiscovery_OnDiscoveryStarted);
            wclBluetoothDiscovery.OnDiscoveryComplete += new wcl.wclBluetoothDiscoveryCompleteEventHandler(wclBluetoothDiscovery_OnDiscoveryComplete);

            wclClient = new wcl.wclClient();
            wclClient.OnDisconnect += new System.EventHandler(wclClient_OnDisconnect);
            wclClient.OnData += new wcl.wclDataEventHandler(wclClient_OnData);
            wclClient.OnConnect += new wcl.wclConnectEventHandler(wclClient_OnConnect);
        }


        private void wclAPI_AfterLoad(object sender, EventArgs e)
        {
            SelectRadio();
        }

        private void wclAPI_AfterUnload(object sender, EventArgs e)
        {
            MessageBox.Show("wclAPI_AfterUnload");
        }

        private void wclAPI_OnChanged(object sender, EventArgs e)
        {
            MessageBox.Show("wclAPI_OnChanged");
        }

        void wclAuthenticator_OnPasskey(object sender, wcl.wclNumericComparisonEventArgs e)
        {
            e.Confirm = true;
        }

        void wclAuthenticator_OnNumericComparison(object sender, wcl.wclNumericComparisonEventArgs e)
        {
            e.Confirm = true;
        }

        private void fmMain_Load(object sender, EventArgs e)
        {
            wclAPI.Load();
        }

        private void fmMain_FormClosed(object sender, FormClosedEventArgs e)
        {

            //if (wclAuthenticator.Active)
            //    wclAuthenticator.Close();

            wclAPI.Unload();

            wclClient.Dispose();
            wclBluetoothDiscovery.Dispose();
            //wclAuthenticator.Dispose();
            wclAPI.Dispose();
        }
       
        private void btDiscover_Click(object sender, EventArgs e)
        {
            if (Radio != null)
            {
                wcl.wclErrors.wclShowError(wclBluetoothDiscovery.Discovery(Radio));
            }
        }

        private void wclBluetoothDiscovery_OnDiscoveryStarted(object sender, wcl.wclBluetoothDiscoveryStartedEventArgs e)
        {
            lvDevices.Items.Clear();
            MessageBox.Show("Started");
        }

        private void wclBluetoothDiscovery_OnDiscoveryComplete(object sender, wcl.wclBluetoothDiscoveryCompleteEventArgs e)
        {
            if (e.Devices == null)
                MessageBox.Show("Error discovering");
            else
                if (e.Devices.Count == 0)
                    MessageBox.Show("Nothing found");
                else
                    for (uint i = 0; i < e.Devices.Count; i++)
                    {
                        wcl.wclBluetoothDevice Device = e.Devices[i];
                        ListViewItem Item = lvDevices.Items.Add(Device.Address);
                        string str = "";
                        Device.GetName(e.Radio, ref str);
                        Item.SubItems.Add(str);
                    }
        }

        private void btConnect_Click(object sender, EventArgs e)
        {
            if (Radio != null)
            {
                if (lvDevices.SelectedItems.Count == 0)
                    MessageBox.Show("Selected device");
                else
                {
                    //wclAuthenticator.Radio = Radio;
                    //wclAuthenticator.Open();

                    wcl.wclBluetoothDevice Device = new wcl.wclBluetoothDevice();

                    string Address = lvDevices.SelectedItems[0].Text;
                    Device.Address = Address;
                    Device.Pair(Radio, "0000");

                    wclClient.BluetoothParams.Address = Address;
                    wclClient.BluetoothParams.Radio = Radio;
                    wclClient.BluetoothParams.Service = new Guid("{71D47FA1-87B6-4629-AB78-77B482AE5316}");
                    wclClient.BluetoothParams.Authentication = true;
                    wclClient.BluetoothParams.Encryption = true;
                    wclClient.Transport = wcl.wclTransport.trBluetooth;
                    wcl.wclErrors.wclShowError(wclClient.Connect());
                }
            }
        }

        private void wclAuthenticator_OnPINRequest(object sender, wcl.wclPINRequestEventArgs e)
        {
            e.PIN = "0000";
        }

        private void wclClient_OnConnect(object sender, wcl.wclConnectEventArgs e)
        {
            if (e.Error != wcl.wclErrors.WCL_E_SUCCESS)
                MessageBox.Show("Unable connect: " + e.Error.ToString());
            else
                MessageBox.Show("Connected");
        }

        private void btDisconnect_Click(object sender, EventArgs e)
        {
            wclClient.Disconnect();
        }

        private void wclClient_OnDisconnect(object sender, EventArgs e)
        {
            MessageBox.Show("Disconnected");
        }

        private void btSend_Click(object sender, EventArgs e)
        {
            string str = edCmd.Text;

            Encoding Coder = Encoding.ASCII;
            byte[] Buf = Coder.GetBytes(str);

            wcl.wclErrors.wclShowError(wclClient.Write(Buf, (uint)str.Length));
        }

        private void wclClient_OnData(object sender, wcl.wclDataEventArgs e)
        {
            Encoding Coder = Encoding.ASCII;
            string str = Coder.GetString(e.Data);

            edAns.Text = edAns.Text + "/r" + str;
        }
    }
}

To summarize what is going on there:
 - wclAuthenticator running on server
 - wclAuthenticator NOT running on client
 - client and server are set to Authentication = True
 - before connecting, client will Pair with the server

Would you consider this a viable workaround until you figure out what is going on with wclAuthenticator having issues when run on both client and server?


 

Sitemap 1 2 3 4 5 6 7