Closed xtremehpx closed 3 years ago
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. https://github.com/BestOwl/MyPhone/blob/9cb86e823e6932e8fce70c4eee34e2f895cd96a4/MyPhone.Demo/MAP.cs#L192
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.
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.
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.
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
Why is this issue closed? It has not been resolved.
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:
SendEvent
function to MCE (PC) which contains the message handle when a new message arrives.GetMessage
function to MSE(Phone) to get the message contentSend PushMessage
function to MSE(Phone)
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())
);
I will try to implement a working demo in the next few days. I will post updates here if I make any progress.
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 :)
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.
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 https://github.com/BestOwl/MyPhone/commit/6f83fa583f50362fa190b6e5121717bee57125f6 to this branch
Let's move the discussion here https://github.com/BestOwl/MyPhone/pull/5 since this issue is closed.
MAP demo does not seem to work with iPhone but Android Phone seems to work. Any suggestions?
System: Windows 10 Pro, 19042.110 Build + iPhone 11
iPhone Log:
Android Log