.NET Components for Mobility

How to deal with SAP ?

Last post 10-07-2008 2:12 PM by alanjmcf. 10 replies.
Page 1 of 1 (11 items)
Sort Posts: Previous Next
  • 09-03-2008 1:55 PM

    How to deal with SAP ?

    Hello group,

    I'm new here so sorry for probably stupid questions. I was trying to make use of my N95's SIM access profile, but I cannot come across some problems. I was using some lines found in another post here. So basically I'm doing this:

                SelectBluetoothDeviceDialog sbdd = new SelectBluetoothDeviceDialog();
                DialogResult res = sbdd.ShowDialog();
                BluetoothAddress btAddr = sbdd.SelectedDevice.DeviceAddress;
                BluetoothDeviceInfo btDevice = new BluetoothDeviceInfo(btAddr);
               
                BluetoothEndPoint bep = new BluetoothEndPoint(btDevice.DeviceAddress, BluetoothService.SimAccess);
                BluetoothClient client = new BluetoothClient();
                client.Connect(bep);
                
                NetworkStream stream = client.GetStream();
                byte[ buffer = new byte[ { 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x01, 0x18, 0x00, 0x00 };
                stream.Write(buffer, 0, buffer.Length);

    Dialog and Connect - OK. Write fails with Socket Error 10053.

      InnerException: System.Net.Sockets.SocketException
           Message="Eine bestehende Verbindung wurde softwaregesteuert\r\ndurch den Hostcomputer abgebrochen"
           Source="System"
           ErrorCode=10053
           NativeErrorCode=10053
           StackTrace:
                bei System.Net.Sockets.Socket.Send(Byte[ buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
                bei System.Net.Sockets.NetworkStream.Write(Byte[ buffer, Int32 offset, Int32 size)
           InnerException:

    I've tried various things, e.g. adding this

    client.Client.SetSocketOption((SocketOptionLevel)BluetoothSocketOptionLevel.RFComm, (SocketOptionName)BluetoothSocketOptionName.Encrypt, true);

    client.Client.SetSocketOption((SocketOptionLevel)BluetoothSocketOptionLevel.RFComm, (SocketOptionName) BluetoothSocketOptionName.XPAuthenticate, true);

    right before connecting or trying to read instead of writing. The read result is empty, btw. So I'm currently not sure, what to do after CONNECT. The buffer, I'm trying to send down, is a CONNECT_REQ (afaik).

    Anybody able to help?

    BTW: Reviewing this I inspected the client object after connect. The property "connected" is false... Seems to be not connected at all?

    Regards

     

     

  • 09-10-2008 8:54 AM In reply to

    Re: How to deal with SAP ?

    Did you make any progress with this?  Or still having the problem?

    Alan J. McFarlane
    http://www.alanjmcf.me.uk/
    Please follow-up in the newsgroup for the benefit of all.
    Have I helped? Consider visiting my Amazon wishlist, see my homepage.
  • 09-19-2008 11:56 AM In reply to

    Re: How to deal with SAP ?

    Hi alanjmcf,

    thanks for your response and sorry for the delay. I was on vacation and - no I didn't made any progress on this issue. Meanwhile I got some hints from Torstein, having had the same problems a couple of month ago. I'll give his results a try and will report on this later on.

    Kind regards

    Neil

    UPDATE: Torstein's sample code does show the same result. This leads me to the assumtpion, that either InTheHand or my N95 SAP has a problem. The exception is the same: I can't write down the CONNECT_REQ successully.

     

     

     

  • 09-21-2008 4:36 AM In reply to

    Re: How to deal with SAP ?

    So finally I see no way to make InTheHand run with SAP. The behaviour is reproducable with Nokia N95, N70 and N71. I've got no other phone and no other client stack to test.

    The sequence may be broken down to this couple of lines:

    1      BluetoothAddress btAddr = new BluetoothAddress(mac_of_the_phone);
    2      BluetoothDeviceInfo btDevice = new BluetoothDeviceInfo(btAddr);
    3      BluetoothEndPoint bep = new BluetoothEndPoint(btDevice.DeviceAddress, BluetoothService.SimAccess);

    4      BluetoothClient client = new BluetoothClient();
    5     
    client.Connect(bep);

    6      NetworkStream stream = client.GetStream();
    7      byte[ buffer = new byte[ { 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x10, 0x00, 0x00, 0x00 };
    8      stream.Write(buffer, 0, buffer.Length);

    9      int bytesread = stream.Read(buffer, 0, buffer.Length);

    The client is a Dell Latitude D820 with internal Dell BT 350 and Microsoft XP BT stack. SIM acces is enabled on all mentioned phones. The only consistent behavior of InTheHand here is, that line 5 always fails with a self explaining error message, if SIM access isn't enabled.

    If the phone is not already paired, the phone pops up a 16 (!) digit pin request box. After OK heavy BT activity seems to go on for ~30 secs (to be seen on the phone), but finally the programm excepts in line 5 with "Cannot connect". If the phone is paired outside the program using the MS stack means and providing the required 16 digit PIN, line 5 is passed OK, but the phone seems to disconnect ASAP (BT LED changes to inactive).

    If the program runs across line 9, bytesread is 0, but shouldn't, because the written request is a CONNECT_REQ (CONNECT_RSP expected). If I single step from line 6, already line 8 fails with "Cannot write into a closed socket", another indication, that the connection has not been established or has already been closed.

    I cannot make any positive attemtp to provide either PIN or any other socketoption, all attempts rejected with errors. 

    I'm going to give up messing around with this unfortunately...

     

  • 09-22-2008 3:20 PM In reply to

    Re: How to deal with SAP ?

    ...and finally a brandnew N82 shows the same symptoms. No Go.

     Is here really nobody able to help or to reproduce the scenario??

    Regards

  • 09-23-2008 5:52 AM In reply to

    Re: How to deal with SAP ?

    I'm afraid I don't have a device supporting SAP to verify on. Have you checked that you can connect to other profiles on the device to narrow down the issue. Also did you set the Encrypt property to true before connecting? SAP requires an encrypted connection. The specification also requires that the devices are bonded (paired) with a 16 digit key before the connection is attempted.

    Peter

    Peter Foot
    Microsoft Device Application Development MVP
    www.peterfoot.net | www.inthehand.com
  • 09-23-2008 3:26 PM In reply to

    Re: How to deal with SAP ?

    Yes, I have also set client.Encrypt = true, no change. As I said earlier, the device MUST be bonded before, because otherwise the connection cannot be established at all.

    The connection is closed a second after being established for unknown reasons.

  • 09-26-2008 6:48 AM In reply to

    Re: How to deal with SAP ?

    Hi Peter,

    I was near to give up the last days, because I didn't find any Nxx (tried N70, N82, N95, N51), capable of answering the CONNECT_REQ with a valid CONNECT_RESP. Everytime the connection was torn down by the Nxx with no further notice. It seems, that the connection release is a result of the CONNECT_REQ, because the BT acivity LED on the phone is active for about 5 secs after client.Connect() without stream.Write(), but is only active for about 3 secs after client.Connect() followed by a stream.Write(). What is that special with Nokia's SAP realisation?

    I could not find any error in the SAP connection establishment sequence itself.

    Today I took my Windows Mobile 6.1 HTC Kaiser (aka T-Mobile MDA III), without too much hopes. But - surprisingly - it runs like a charme! Exactly the same sequence, with one addition: I had to add the line

    client.Encrypt = true;

    right before the client.Connect(). This has been tried 1000 times before and did make absolutely no difference in the Nokia behavior, but resulted in a valid CONNECT_RESP on WM 6.1

    How to interpret this? Is there a chance to come closer to the problem, probably by debug or trace means?

    Regards

     

     

  • 09-27-2008 5:05 AM In reply to

    Re: How to deal with SAP ?

    Although nobody seems to be able to help me out here, I would like to share the latest results.

    Windows Mobile is running perfectly. CONNECT_REQ, CONNECT_RSP, STATUS_IND, TRANSFER_ATR_REQ, TRANSFER_ATR_RESP and after that one may issue the TRANSFER_APDU_REQ and get the _RESPs.

    But the N-Series devices WONT CONNECT AT ALL.Pairing outside the app, providing a 16 digit PIN - Result: Connect OK, Exception in stream.Write() ("Stream closed by host").

    Meanwhile I suppose, that there is a special math on the 16 digit passkey, which is checked by Nokia. Does anybody have a "valid" car kit 16 digit passcode? 

    Regards

  • 10-02-2008 3:23 PM In reply to

    Re: How to deal with SAP ?

    So, now I got a D-LINK DBT 122, and after some hackings to make this stick run with the native Windows XP SP 2 BT stack, everything works fine. client.Encrypt is not required and a TRANSFER_ATR_REQ is also not necessary. N82 connects fine, so it seems to be a matter of the stick's firmware?!? Although the DELL 350 claims to support 128 bit encryption, it seems to not do that at all?!

     A bit surprised and clueless... Comments welcome!

  • 10-07-2008 2:12 PM In reply to

    Re: How to deal with SAP ?

    I'm glad you got it working.  No other useful comment from here sadly. :-,(  Not helping you, but I'll try and remember that issue in case someone else reports such an issue in the future. 

    Alan

    Alan J. McFarlane
    http://www.alanjmcf.me.uk/
    Please follow-up in the newsgroup for the benefit of all.
    Have I helped? Consider visiting my Amazon wishlist, see my homepage.
Page 1 of 1 (11 items)
Copyright © 2001-2008 In The Hand Ltd. All rights reserved. Terms of Use and Privacy Policy.