Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send bMessage to Message Access Server from Windows using 32feet.net library in C#

I'm trying to send a bMessage from C# code on a Win7 PC to a Samsung Note 2 phone. I have the 32feet Bluetooth library and am using Visual Studio 2013 Community Edition.

Here is the code that I currently have:

    string sendMessage = "";
    sendMessage = File.ReadAllText(file_path);

    BluetoothClient btClient = new BluetoothClient();
    btClient.Connect(btEp);
    Stream clientStream = btClient.GetStream();

    using (StreamWriter utfWriter = new StreamWriter(clientStream, Encoding.UTF8))
    {
        utfWriter.Write(sendMessage);
    }

btEp is a Bluetooth endpoint passed to the function to send the message and defined elsewhere as follows:

BluetoothEndPoint BtEp;

This is built using the variables:

BtEp = new BluetoothEndPoint(device.DeviceInfo, mapServiceId);

Both values are taken from the device at runtime and take the following values during execution:

-       mapServiceId    {00001132-0000-1000-8000-00805f9b34fb}  System.Guid
+       BtEp    {BC20A4164A8C:0000113200001000800000805f9b34fb} InTheHand.Net.BluetoothEndPoint

With BC20A4164A8C being the device address as reported by the device.

The connection to the phone appears to be working and accessing the correct service because when I execute the code the phone prompts me to ask if I am willing to accept a connection to the message server from my PC. This occurs when the statement 'btClient.Connect(btEp);' is executed.

To the best of my knowledge the text file that I read and send to the phone over the stream is a correctly formatted bMessage as defined by the Bluetooth MAP spec and verified elsewhere. It is constructed as follows:

BEGIN:BMSG
VERSION:1.0
STATUS:UNREAD
TYPE:SMS_GSM
FOLDER:TELECOM/MSG/OUTBOX
BEGIN:VCARD
    VERSION:2.1
    N:(redacted)
    TEL:(redacted)
END:VCARD
BEGIN:BENV
    BEGIN:VCARD
        VERSION:2.1
        N:(redacted)
        TEL:(redacted)
    END:VCARD
    BEGIN:BBODY
        ENCODING:G-7BIT
        LENGTH:47
        BEGIN:MSG
            This is a short message
        END:MSG
    END:BBODY
END:BENV
END:BMSG

I've replaced personally identifiable info with (redacted) but the actual text file contains proper names and numbers. I'm based in the UK so SMS_GSM should be correct as far as I know.

Any assistance would be greatly appreciated!

Update: I have installed a Bluetooth terminal on the target phone and verified that the message is being received by sending the same data to a virtual port on the device rather than to the Message Access Server. Not sure if it was an issue with the terminal program but the final line of the message was being appended to the front and missed from the end. I have added a line break to the end of the file which has fixed this issue but still no joy when I send the bMessage to the MAS.

I have tried a number of different stream writing approaches too:

1) removing the StreamWriter Encoding wrapper - same result 2) sending each byte in sequence from a loop - similar result, still no action on the phone.

If there are any Bluetooth comms experts out there I'd really appreciate some advice! Doesn't necessarily have to be Message Access Profile-specific nor, necessarily, C#.

I guess that my next step would be to see if I can find a modern car that has Bluetooth pairing for MAP services and can connect to the phone and maybe sniff the packets when using similar functionality???

03/02/16 - Have sniffed packets between my phone and a new car whilst sending/receiving messages in both directions and compared this to sniffed packets between my PC/code and phone (thanks Android! dev options natively allow BT packet logging and was able to dump this into Wireshark for analysis). My code is using BluetoothClient which operates over RFCOMM in the BT protocol stack, whereas the car uses L2CAP. L2CAP is a level below RFCOMM in the BT stack and 32Feet has an equivalent L2CapClient to operate at this level. Have implemented this but it throws an error. It turns out that although L2CAP is supported not all profiles that use it are and MAP appears to be one of those.

I'm going to answer this question to give possible options to anyone else who stumbles across it.

like image 885
fraggle Avatar asked Dec 04 '15 15:12

fraggle


1 Answers

Think I've established that doing this using 32Feet/C# is not going to be viable. If you want to access a phone's Bluetooth Message Access Server/Profile/Client (MAS MAP MAC) you cannot do so using the high level functions in the 32Feet.Net library. Instead you would need to use lower level code in C++ as detailed on MSDN:

https://msdn.microsoft.com/en-us/library/windows/hardware/ff536674%28v=vs.85%29.aspx

19/02/16 - I have managed to use the Bluetooth link to the Hands Free Profile on my mobile to initiate a call (this was something else I wanted to do but I mistakenly thought SMS would be easier!). I have used AT commands to achieve this. I then tried using AT commands to send SMS too but apparently my phone doesn't implement the AT commands for this in its implementation of HFP. So still no text messages.

I have a few packet sniffs of SMS over Bluetooth between my phone and a car so will look at how this is handled at some point. I do need to get the SMS sorted but can run with simple voice call initiation for the current stage of the project.

like image 79
fraggle Avatar answered Nov 10 '22 00:11

fraggle