Author Topic: Secure ChatServer  (Read 26940 times)

LucaUWF

  • Guest
Secure ChatServer
« on: October 20, 2012, 03:20:20 PM »
Hi,

I have the chat client sample running in Authentication mode and that seems to work fine, my device listens and accepts the Auth. connection.

Ultimately I need to have the PC behaving as Multiple Secure Servers for SPP, so my plan is to take the OPPSecureServer and MultiBtOPPServers samples and modify them for the serial data connection.

Unfortunately I'm running into a problem in getting the Auth. connection to work. Upon my device to connect to the server the server receives the PIN request on the wclAuthenticator_OnPINRequest event and supplies the correct pin, but then there is no connection and my device throws out the following error: RFC_RES_ACK_TIMEOUT.

In the Bluetooth Device Explorer under windows the devices looks to be paired... am I missing something?

Thanks in advance, my code is below.

Code: [Select]

public partial class fmMain : Form
    {
        private wcl.wclAPI wclAPI;
        private wcl.wclBluetoothDiscovery wclBluetoothDiscovery;
        private wcl.wclServer wclServer;
        private wcl.wclAuthenticator wclAuthenticator;


        public fmMain()
        {
            InitializeComponent();

            wclAPI = new wcl.wclAPI();

            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.OnAuthenticationRequest += new wcl.wclAuthenticationRequestEventHandler(wclAuthenticator_OnAuthenticationRequest);
            wclAuthenticator.OnPINRequest += new wcl.wclPINRequestEventHandler(wclAuthenticator_OnPINRequest);

            wclServer.BluetoothParams.Authentication = true;
            wclServer.BluetoothParams.Name = "WCL Serial Server";
        }

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

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

            wclServer.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(Radios[0]);
            if (Radio == null)
                MessageBox.Show("No Bluetooth API was found.");
            return Radio;
        }

        private void btListen_Click(object sender, EventArgs e)
        {
            if (wclServer.State != wcl.wclServerState.ssClosed)
                MessageBox.Show("Server is active");
            else
            {
                wcl.wclBluetoothRadio Radio = GetSelectedRadio();
                if (Radio != null)
                {

                   
                    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;
                    }
                    else
                    {
                        wclServer.Transport = wcl.wclServerTransport.stBluetooth;
                        wclServer.BluetoothParams.Radio = Radio;
                        wclServer.BluetoothParams.Authentication = true;
                        wclServer.BluetoothParams.Encryption = false;
                        wclServer.BluetoothParams.Service = wcl.wclUUIDs.SerialPortServiceClass_UUID;
                        wcl.wclErrors.wclShowError(wclServer.Listen());
                    }
                }
            }
        }

        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)
        {
            wcl.wclBluetoothRadio Radio = GetSelectedRadio();
            wcl.wclBluetoothDevice Device = new wcl.wclBluetoothDevice();
            Device.Address = wclServer.Address;
            Device.Unpair(Radio);
            listBox.Items.Add("Disconnected " + wclServer.Address + " " + wclServer.DeviceName);
        }

        private void btClose_Click(object sender, EventArgs e)
        {
            wclServer.Close();

        }

        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)
        {
            e.PIN = "1234";
        }

        private void wclAuthenticator_OnAuthenticationRequest(object sender, wcl.wclAuthenticationRequestEventArgs e)
        {
            e.Answer = e.Value;
            e.Confirm = true;
        }
    }


Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3675
  • Karma: 1000
    • Wireless Communication Libraries
Re: Secure ChatServer
« Reply #1 on: October 20, 2012, 04:12:37 PM »
Hi,

Make sure that there is no other SPP server running. Usualy if you use non MS BT driver, a driver has its own server listening on SPP so your device connects to this service.

Also, check that service available on PC (you cansimple run BluetoothDiscovery on other PC and check what services are available). If there are 2 SPP service than it may be a problem.

LucaUWF

  • Guest
Re: Secure ChatServer
« Reply #2 on: October 20, 2012, 05:54:27 PM »
Hi,

The SPP service under windows is set to Manual/Disable, if this is what you mean.
Once the device is paired using the secure chat service I can then "Connect Bluetooth Serial Port" manually to the device which completes the connection under the windows API and the virtual comm port.


This is an application I will need to deploy to other users so can't guarantee what their Blutooth setup will be or how many SPP services may be running, does this mean that what I want to do may not be achievable?

Thanks for your help.

 

LucaUWF

  • Guest
Re: Secure ChatServer
« Reply #3 on: October 20, 2012, 06:09:30 PM »
Just to update...

I stripped things back a little, and went back to the original ChatServer code and removed the Authentication configuration from the client.
The connection then works, ideally though it needs to be authenticated.


Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3675
  • Karma: 1000
    • Wireless Communication Libraries
Re: Secure ChatServer
« Reply #4 on: October 20, 2012, 08:58:46 PM »
Hi,

I will check what can be wrong and back to you.

LucaUWF

  • Guest
Re: Secure ChatServer
« Reply #5 on: October 20, 2012, 10:23:50 PM »
Hi mike,

I managed to resolve the problem. For whatever reason it is related to changing the radio name, once I removed this from the sample code I imported it worked a charm.

Now I have a auth. Multi server spp the way I wanted... It would be nice to be able to change the name, but this didnt appear to work anyway under ms or broadcom stacks.

All I need to do now is sort out a redist. package and I think its good to go, so I hope to place an order soon.

Thanks for the assistance.

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3675
  • Karma: 1000
    • Wireless Communication Libraries
Re: Secure ChatServer
« Reply #6 on: October 21, 2012, 08:42:07 AM »
Hi,

May be your device connects by name?

Any way, to change local radio name under MS stack your application must run with administrative rights. To change local radio name under WidComm (on WinXP) you have to use wcl2wbt.dll from WCL\Redist\old folder.

LucaUWF

  • Guest
Re: Secure ChatServer
« Reply #7 on: October 21, 2012, 11:48:47 AM »
Couple of things.

The device definitely connects by address.
The name is not known anyway until after discovery at which time the server is running and the name change attempt was made.
I have admin rights, and can manually change it.

I'll do a bit more on this though and have a look into the extra dll you mentioned, I don't recall seeing anything on this in the api doc, but I probably missed it.

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3675
  • Karma: 1000
    • Wireless Communication Libraries
Re: Secure ChatServer
« Reply #8 on: October 21, 2012, 12:47:44 PM »
Hi,

Yes, you may have admin rights and can change name manually, but to change a name from your application, your application must run with admin rights.

Please take a look on the following links:

http://www.btframework.com/howto.htm#redist
http://forum.btframework.com/index.php/topic,955.0.html
http://forum.btframework.com/index.php/topic,433.0.html

LucaUWF

  • Guest
Re: Secure ChatServer
« Reply #9 on: October 21, 2012, 03:08:08 PM »
Hi Mike,

Sorry, I misread your previous post.
Requiring Admin rights isn't really an option as I believe the user has to have administrator privileges on that machine in the first place, and I cannot guarantee this, please correct if I am wrong, and I will certainly try and test this. Assuming that is right, what other potential problems might there by when not running with Admin rights?


Having read through the links you provided and also looking at some other posts, e.g. http://forum.btframework.com/index.php/topic,1670.0.html
I am now wondering if this is really going to do what I want. Currently the application I deploy is a single ClickOnce installer for all operating systems which include XP, Vista, Win7 both 32 and 64 bit on vista/7.
So the plan I had was to just use the x86 builds and have my app run as x86 since it doesn't use any x64 optimisations anyway. However, there's now the complexity of the various stacks and these two remarks from the posts I have seen so far:

  • Toshiba doesn't provide API for wclAuthenticator support as for Server side. wclAuthenticator works on Toshiba only for Client connection.
  • wcl2wbt.dll - this DLL from redist folder has been built with a latest WidComm SDK but it may have some issues when WidComm is used with Microsoft Bluetooth Drivers.

In the case of the Toshiba note above I'm guessing this means I would have to remove authentication to support Toshiba in the same way I would the other stacks.
I don't really follow the second item, can you elaborate on "Some issues" and maybe suggest when you are likely to find Widcomm stacks on MS Drivers... is this typical?
 
Thanks

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3675
  • Karma: 1000
    • Wireless Communication Libraries
Re: Secure ChatServer
« Reply #10 on: October 22, 2012, 06:20:06 AM »
Hi,

Requiring Admin rights isn't really an option as I believe the user has to have administrator privileges on that machine in the first place, and I cannot guarantee this, please correct if I am wrong, and I will certainly try and test this. Assuming that is right, what other potential problems might there by when not running with Admin rights?

There was a link to manifest file which gives admin rights to your application.

In the case of the Toshiba note above I'm guessing this means I would have to remove authentication to support Toshiba in the same way I would the other stacks.
I don't really follow the second item, can you elaborate on "Some issues" and maybe suggest when you are likely to find Widcomm stacks on MS Drivers... is this typical?

Unfortunately Toshiba doesn't provide any way to handle authentication wen it runs as a server. So its better to disable authentication when your app runs on Toshiba stack. With any other you just have to redistribute your aplication and wcl2wbt.dll. That's all you have to do to make it working. WD on MS: MS allows to expand BT stack on Vista/Win 7 and actualy there is no WD driver on those platforms. Win7/Vista always runs MS but WD is installed as extention. WCL detects it as MS stack. Current WCL release has no any issue when it works in such configuration and can handle authentication for client and for server with any stack (except Toshiba runs as a server).

So I do not see any problem to develop app as you need.

LucaUWF

  • Guest
Re: Secure ChatServer
« Reply #11 on: October 23, 2012, 05:15:19 PM »
Hi Mike,

Thanks for the info and the assistance to date!
We'll submit our order in due course.

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3675
  • Karma: 1000
    • Wireless Communication Libraries
Re: Secure ChatServer
« Reply #12 on: October 23, 2012, 05:29:35 PM »
Hi,

You are very welcome! Let me know if you have any question or find any issue. I'll be happy to help.

 

Sitemap 1 2 3 4 5 6 7