MAP demo doesn't work with iPhone
xtremehpx opened this issue · 14 comments
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:
Selected: X’s iPhone Bluetooth#Bluetooth30:e3:7a:62:d5:67-60:83:73:83:12:a6 Available RFComm services for this devices: Bluetooth#Bluetooth30:e3:7a:62:d5:67-60:83:73:83:12:a6#RFCOMM:00000000:{00001132-0000-1000-8000-00805f9b34fb} Bluetooth#Bluetooth30:e3:7a:62:d5:67-60:83:73:83:12:a6#RFCOMM:00000000:{02030302-1d19-415f-86f2-22a2106a0a77} Bluetooth#Bluetooth30:e3:7a:62:d5:67-60:83:73:83:12:a6#RFCOMM:00000000:{00000000-deca-fade-deca-deafdecacafe} Bluetooth#Bluetooth30:e3:7a:62:d5:67-60:83:73:83:12:a6#RFCOMM:00000000:{0000112f-0000-1000-8000-00805f9b34fb} Bluetooth#Bluetooth30:e3:7a:62:d5:67-60:83:73:83:12:a6#RFCOMM:00000000:{0000111f-0000-1000-8000-00805f9b34fb} Connecting... 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 Returned package: Opcode: Success 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-90-5D-20-07-4A-00-13-BB-58-2B-40-42-0C-11-DB-B0-DE-08-00-20-0C-9A-66 MNS: Start advertising MNS service Wait for 1 seconds MNS: Sending 82-00-4A-CB-00-00-00-01-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-46-00-13-BB-58-2B-40-42-0C-11-DB-B0-DE-08-00-20-0C-9A-66 Opcode: PutAlter Returned packet: D3-00-03 Opcode: 211 MNS: Failed to call SetNotificationRegistration Enter any key to exit...
Android Log
Selected: Pixel 2 XL Bluetooth#Bluetooth30:e3:7a:62:d5:67-08:d4:6a:1a:b4:e9 Available RFComm services for this devices: Bluetooth#Bluetooth30:e3:7a:62:d5:67-08:d4:6a:1a:b4:e9#RFCOMM:00000000:{00001112-0000-1000-8000-00805f9b34fb} Bluetooth#Bluetooth30:e3:7a:62:d5:67-08:d4:6a:1a:b4:e9#RFCOMM:00000000:{0000111f-0000-1000-8000-00805f9b34fb} Bluetooth#Bluetooth30:e3:7a:62:d5:67-08:d4:6a:1a:b4:e9#RFCOMM:00000000:{00001132-0000-1000-8000-00805f9b34fb} Bluetooth#Bluetooth30:e3:7a:62:d5:67-08:d4:6a:1a:b4:e9#RFCOMM:00000000:{0000112f-0000-1000-8000-00805f9b34fb} Bluetooth#Bluetooth30:e3:7a:62:d5:67-08:d4:6a:1a:b4:e9#RFCOMM:00000000:{00001105-0000-1000-8000-00805f9b34fb} Bluetooth#Bluetooth30:e3:7a:62:d5:67-08:d4:6a:1a:b4:e9#RFCOMM:00000000:{0000112d-0000-1000-8000-00805f9b34fb} Connecting... 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 Returned package: Opcode: Success A0-00-32-10-00-FF-FE-46-00-13-BB-58-2B-40-42-0C-11-DB-B0-DE-08-00-20-0C-9A-66-CB-01-00-00-00-4A-00-13-BB-58-2B-40-42-0C-11-DB-B0-DE-08-00-20-0C-9A-66 MNS: Start advertising MNS service Wait for 1 seconds MNS: Sending 82-00-4A-CB-00-00-00-01-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-46-00-13-BB-58-2B-40-42-0C-11-DB-B0-DE-08-00-20-0C-9A-66 Opcode: PutAlter Returned packet: A0-00-08-CB-01-00-00-00 Opcode: Success Enter any key to exit... Connection received Stoping Advertising Opcode: Connect Unhandled exception. System.AggregateException: One or more errors occurred. (A method was called at an unexpected time. (0x8000000E)) ---> System.InvalidOperationException: A method was called at an unexpected time. (0x8000000E) at Windows.Devices.Bluetooth.Rfcomm.RfcommServiceProvider.StopAdvertising() at MyPhone.Demo.MAP.Do() in D:\work\git\MyPhone\MyPhone.Demo\MAP.cs:line 84 --- End of inner exception stack trace --- at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken) at System.Threading.Tasks.Task.Wait() at MyPhone.Demo.MAP.Main(String[] args) in D:\work\git\MyPhone\MyPhone.Demo\MAP.cs:line 42
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.
Line 192 in 9cb86e8
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.
MyPhone/MyPhone.OBEX/OBEXHeader.cs
Lines 67 to 70 in ede21d4
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:
- how to actually receive and handle the Notification? and
- how to send message to phone?
1. Receive and handle the Notification
- Establish MNS service connection (SetNotificationRegistration)
- 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. - MCE (PC) send
GetMessage
function to MSE(Phone) to get the message content - 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)
2. Send message to phone
Send 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 6f83fa5 to this branch