Code Monkey home page Code Monkey logo

Comments (14)

BestOwl avatar BestOwl commented on May 28, 2024 1

By building the MNS server on PC before sending the RemoteNotificationRegister request to MSE, I can now receive notifications.

MasObexConnect success is: True
**************************************************
MNS: Start advertising MNS service
Wait for 1 seconds
**************************************************
Sending RemoteNotificationRegister request
Sending request packet: 1
ConnectionId: 0A-90-5E-00
82-00-33-CB-0A-90-5E-00-42-00-25-78-2D-62-74-2F-4D-41-50-2D-4E-6F-74-69-66-69-63-61-74-69-6F-6E-52-65-67-69-73-74-72-61-74-69-6F-6E-00-4C-00-06-0E-01-01
Opcode: PutAlter
Req packet sent. Waiting for reply...1
ReadFromStream:: Opcode: Success
packet length: 3
Header size to read is zero.
Reply packet:
A0-00-03
ResponseCode: Success
No header returned.
Request returned success
RemoteNotificationRegister success is: True
Enter q to exit or other keys to try again...
Connection received
Stoping Advertising
ReadFromStream:: Opcode: Connect
packet length: 26
70
Opcode: Connect
ReadFromStream:: Opcode: PutAlter  #SendEvent from MSE
packet length: 243
66
76
73
Opcode: PutAlter

I can't push to your fork so I push 6f83fa5 to this branch

from myphone.

BestOwl avatar BestOwl commented on May 28, 2024

Sorry for the late reply. It's been a busy week.

This is a known issue. I guess it's because the MAP demo doesn't handle the ConnectionId.

OBEXPacket packet = new OBEXPacket(new Int32ValueHeader(HeaderId.ConnectionId, 1), //TODO: read from MAS

from myphone.

xtremehpx avatar xtremehpx commented on May 28, 2024

Not sure if that is the root cause. I used ConnectionId from OBEX connection call and still getting Response Code "D3". And "D3" is not a valid MAP response code based on the specification document.

Get ConnectionId here:

OBEXConnectPacket packet = new OBEXConnectPacket();
var buf = packet.ToBuffer();
....

OBEXPacket retPacket = await OBEXPacket.ReadFromStream(_reader, packet);
if (retPacket != null)
{
	var bytes = retPacket.ToBuffer().ToArray();
	foreach (var header in retPacket.Headers)
	{
		if (header.HeaderId.Equals(HeaderId.ConnectionId))
		{
			ConnectionHeader = new Int32ValueHeader(HeaderId.ConnectionId, ((Int32ValueHeader)header).Value);
			break;
		}
	}
}

Set ConnectionId here:

OBEXPacket packet = new OBEXPacket(
                ConnectionHeader
                ,new StringValueHeader(HeaderId.Type, "x-bt/MAP-NotificationRegistration")
                ,new AppParamHeader(new AppParameter(AppParamTagId.NotificationStatus, 1))
                ,new BytesHeader(HeaderId.Body, 0x30)
                ,new BytesHeader(HeaderId.EndOfBody, 0x30)
                //,new BytesHeader(HeaderId.Target, MAS_UUID)
                );
            packet.Opcode = Opcode.PutAlter;
Sending MAP client Connection request to Phone MAP server:
80-00-1A-10-00-FF-FF-46-00-13-BB-58-2B-40-42-0C-11-DB-B0-DE-08-00-20-0C-9A-66
Opcode: Connect
Waiting reply packet:
Opcode: Success
Reply packet:
A0-00-32-10-00-0F-A0-46-00-13-BB-58-2B-40-42-0C-11-DB-B0-DE-08-00-20-0C-9A-66-CB-E0-65-00-1D-4A-00-13-BB-58-2B-40-42-0C-11-DB-B0-DE-08-00-20-0C-9A-66
ResponseCode: Success
Target: BB-58-2B-40-42-0C-11-DB-B0-DE-08-00-20-0C-9A-66
ConnectionId: E0-65-00-1D
Who: BB-58-2B-40-42-0C-11-DB-B0-DE-08-00-20-0C-9A-66
Sending MAP client notification registration request to Phone MAP server:
82-00-3B-CB-E0-65-00-1D-42-00-25-78-2D-62-74-2F-4D-41-50-2D-4E-6F-74-69-66-69-63-61-74-69-6F-6E-52-65-67-69-73-74-72-61-74-69-6F-6E-00-4C-00-06-0E-01-01-48-00-04-30-49-00-04-30
Opcode: PutAlter
Waiting reply packet:
Reply packet:
D3-00-03
ResponseCode: 211
Remote request failed.

from myphone.

xtremehpx avatar xtremehpx commented on May 28, 2024

Looks like "D3" is from OBEX specification,
No more than one Reliable OBEX Session shall exist at any time on each transport connection, which is equivalent to the L2CAP channel connection. If a CREATE SESSION command is issued while an active Reliable Session already exists, the operation shall be rejected with the Service Unavailable (0xD3) response code. If a CREATE SESSION command is issued while a suspended Reliable Session exists, the operation may be rejected with the Service Unavailable (0xD3) response code, or the suspended session may be removed and a new Reliable Session created.

from myphone.

xtremehpx avatar xtremehpx commented on May 28, 2024

If connection id is NOT reversed, then the response code is no longer 0xD3 but 0x90. However, no valid data is return when we continue making the Get request.

if (BitConverter.IsLittleEndian)
{
Array.Reverse(ret);
}

Sending RemoteNotificationRegister request
Sending request packet: 1
02-00-46-CB-1D-00-65-E0-42-00-25-78-2D-62-74-2F-4D-41-50-2D-4E-6F-74-69-66-69-63-61-74-69-6F-6E-52-65-67-69-73-74-72-61-74-69-6F-6E-00-4C-00-06-0E-01-01-46-00-13-BB-58-2B-40-42-0C-11-DB-B0-DE-08-00-20-0C-9A-66
Opcode: Put
Req packet sent. Waiting for reply...1
ReadFromStream:: Opcode: Continue
packet length: 3
Header size to read is zero.
Reply packet:
90-00-03
ResponseCode: Continue
No header returned.
Sending request packet: 2
02-00-03
Opcode: Put
Req packet sent. Waiting for reply...2
ReadFromStream:: Opcode: Continue
packet length: 3
Header size to read is zero.
...

I created additional MAS functions to test. However currently the only one worked is OBEX Connect request. My fork

from myphone.

BestOwl avatar BestOwl commented on May 28, 2024

Why is this issue closed? It has not been resolved.

from myphone.

xtremehpx avatar xtremehpx commented on May 28, 2024

Why is this issue closed? It has not been resolved.

I was able to get remote notification to work by following changes in the Connection Id handling:

public override void FromBytes(byte[] bytes)
        {
            if (HeaderId.Equals(HeaderId.ConnectionId))
            {
                Value = IPAddress.NetworkToHostOrder(BitConverter.ToInt32(bytes));
            }
            else
            {
                Value = BitConverter.ToInt32(bytes);
            }
            
        }

        public override byte[] ToBytes()
        {
            byte[] ret;

            if (HeaderId.Equals(HeaderId.ConnectionId))
            {
                ret = BitConverter.GetBytes(IPAddress.HostToNetworkOrder(Value));
            }
            else
            {
                ret = BitConverter.GetBytes(Value);
            }
            return ret;
        }

my changes are available from my fork as well.

BTW, do you have suggestions for:

  1. how to actually receive and handle the Notification? and
  2. how to send message to phone?

from myphone.

BestOwl avatar BestOwl commented on May 28, 2024

1. Receive and handle the Notification

  1. Establish MNS service connection (SetNotificationRegistration)
  2. Once the MNS service connection is established, the MSE (phone) will send SendEvent function to MCE (PC) which contains the message handle when a new message arrives.
  3. MCE (PC) send GetMessage function to MSE(Phone) to get the message content
  4. Show the toast notification on MCE(PC) (For Windows 10/11, we can use this library, https://github.com/CommunityToolkit/WindowsCommunityToolkit/tree/main/Microsoft.Toolkit.Uwp.Notifications)

from myphone.

BestOwl avatar BestOwl commented on May 28, 2024

2. Send message to phone

Send PushMessage function to MSE(Phone)

from myphone.

xtremehpx avatar xtremehpx commented on May 28, 2024

2. Send message to phone

Send PushMessage function to MSE(Phone)

I have been working on PushMessage for couple days and no success so far. Any working example by chance? My example is attached below.

In terms of getting the notification from the phone, I understand the high level flow. The demo code has 1 (2), 3 implemented but I don't see the GetMessage been triggered. No success so far.

PushMessage OBEX object payload with no success:

StringBuilder mssg = new StringBuilder();
            mssg.AppendLine("BEGIN:BMSG");
            mssg.AppendLine("VERSION: 1.0");
            mssg.AppendLine("STATUS: UNREAD");
            mssg.AppendLine("TYPE: SMS_GSM");
            mssg.AppendLine("FOLDER:telecom/msg/outbox");
            mssg.AppendLine("BEGIN: VCARD");
            mssg.AppendLine("VERSION:2.1");
            mssg.AppendLine("N: null");
            mssg.AppendLine("TEL: 1234567891");
            mssg.AppendLine("END: VCARD");
            mssg.AppendLine("BEGIN:BENV");
            mssg.AppendLine("BEGIN:BBODY");
            mssg.AppendLine("CHARSET:UTF - 8");
            mssg.AppendLine("LENGTH: 51");
            mssg.AppendLine("BEGIN: MSG");
            mssg.AppendLine("Joey Pigza Swallowed the Key;");
            mssg.AppendLine("END: MSG");
            mssg.AppendLine("END:BBODY");
            mssg.AppendLine("END:BENV");
            mssg.AppendLine("END:BMSG");

            OBEXPacket packet = new OBEXPacket(
                Opcode.PutAlter
                , ConnectionHeader
                , new TypeHeader("x-bt/message")
                , new NameHeader("telecom/msg/outbox")
                , new BodyHeader(HeaderId.Body, mssg.ToString())
                );

from myphone.

BestOwl avatar BestOwl commented on May 28, 2024

I will try to implement a working demo in the next few days. I will post updates here if I make any progress.

from myphone.

xtremehpx avatar xtremehpx commented on May 28, 2024

I will try to implement a working demo in the next few days. I will post updates here if I make any progress.

Sounds good! I will update if I have success as well :)

from myphone.

xtremehpx avatar xtremehpx commented on May 28, 2024

I fixed the bmessage format and it is working with the demo code. The only thing really need the fix is the Connection Id. I have not tested receiving notification yet though.

from myphone.

BestOwl avatar BestOwl commented on May 28, 2024

Let's move the discussion here #5 since this issue is closed.

from myphone.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.