Here is the wireshark output of the reboot command that works when issued from my PBX. I would like to duplicate this in an external program. Note that 10.10.220.109 is the phone and 10.10.220.112 is the PBX. Can someone help me with the code needed in C#?
Request-Line: NOTIFY sip:101@10.10.220.109:5062 SIP/2.0
Method: NOTIFY
Request-URI: sip:101@10.10.220.109:5062
[Resent Packet: False]
Message Header
Via: SIP/2.0/UDP 10.10.220.112:5060:BRANCH=Z9Hg4Bk-D8754Z-69280EIDEF09C232-1---D8754Z-;rport
Max-Forwards: 70
Contact: <sip:101@10.10.220.112:5060>
To: <sip:101@10.10.220.112>
From: <sip:101@10.10.220.112>;tag=b85d0108
Call-ID: NjJmMjZjYjY2NTEzZmFmMWQ4NTAwNGJkN0Ix0TIzYWE.
CSeq: 1 NOTIFY
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REGISTER, SUBSCRIBE, NOTIFY, REFER, INFO, MESSAGE
Supported: replaces
User-Agent: 3CXPhoneSystem 14.0.48169.513 (48654)
Event: check-sync;reboot=true
Content-Length: 0
A couple of things that I found curious (I'm new to SIP). In the message header the "To" and "From" are both using the IP of the PBX, while in the Request-Line it uses the IP of the phone. Also, the Message Header references port 5060, while the Request-Line uses 5062. I don't know if any of the hieroglyphics represents authentication information, but if that is needed, please offer guidance there as well.
Finally, I assume if I set reboot=false, the phone will auto-provision without a reboot. Is that true, or do I need a different command?
Reboot phone using Notify
Re: Reboot phone using Notify
Did my stack overflow answer get you close http://stackoverflow.com/a/40985084/75658?
If you have that phone registered with the sipsorcery server you can email me (admin@sipsorcery.com) the public socket for it an I'll try sending it the NOTIFY request.
If you have that phone registered with the sipsorcery server you can email me (admin@sipsorcery.com) the public socket for it an I'll try sending it the NOTIFY request.
Re: Reboot phone using Notify
Aaron, it got me really close, which is why I posted the pcap example. It sends the notify, but the port numbers were backwards. Where my pcap has port 5060 I got 5061, and where the pcap had 5062 I got 5060. And I don't understand why my PBX has the IP of the PBX in both the from and to. But this is what I need to match apparently to get this to work. I can't find a syntax reference, so I don't know where to begin to adjust your code. The other issue is it hangs on waitone which I assume it's waiting for a valid response from the phone?
Your help is greatly appreciated.
Your help is greatly appreciated.
Re: Reboot phone using Notify
I suspect the main thing you're missing is the Event header which is what's asking the phone to reboot "Event: check-sync;reboot=true", I've added it to the sample below. Note in the code below you may need to change the IP addresses and ports used in the SIP URIs.
Code: Select all
using System;
using System.Net;
using System.Threading;
using SIPSorcery.SIP;
using SIPSorcery.SIP.App;
using SIPSorcery.Sys;
using SIPSorcery.Sys.Net;
namespace SipSendNotify
{
class Program
{
private const int _defaultSIPUdpPort = SIPConstants.DEFAULT_SIP_PORT; // The default UDP SIP port.
private static SIPTransport _sipTransport;
static void Main(string[] args)
{
try
{
// Configure the SIP transport layer.
_sipTransport = new SIPTransport(SIPDNSManager.ResolveSIPService, new SIPTransactionEngine());
// Use default options to set up a SIP channel.
var localIP = LocalIPConfig.GetDefaultIPv4Address(); // Set this manually if needed.
int port = FreePort.FindNextAvailableUDPPort(_defaultSIPUdpPort);
var sipChannel = new SIPUDPChannel(new IPEndPoint(localIP, port));
_sipTransport.AddSIPChannel(sipChannel);
SIPCallDescriptor callDescriptor = new SIPCallDescriptor("username", null, "sip:101@10.10.220.109:5062", "sip:101@10.10.220.112", null, null, "Event: check-sync;reboot=true", null, SIPCallDirection.Out, null, null, null);
SIPNonInviteClientUserAgent notifyUac = new SIPNonInviteClientUserAgent(_sipTransport, null, callDescriptor, null, null, (monitorEvent) => { Console.WriteLine("Debug: " + monitorEvent.Message); });
notifyUac.ResponseReceived += (resp) => { Console.WriteLine(resp.ToString()); };
notifyUac.SendRequest(SIPMethodsEnum.NOTIFY);
ManualResetEvent mre = new ManualResetEvent(false);
mre.WaitOne();
}
catch (Exception excp)
{
Console.WriteLine("Exception Main. " + excp);
}
finally
{
Console.WriteLine("Press any key to exit...");
Console.ReadLine();
}
}
}
}
Re: Reboot phone using Notify
I eventually got my command to look EXACTLY like the command the PBX sends, yet it still doesn't work. I now wonder if there is some kind of authentication that takes place prior to sending the Notify? i ended up using the .Net UDP protocol library to send the command. I suppose it is time to start reading a SIP reference.
Re: Reboot phone using Notify
If the authentication was in the NOTIFY request then you'd see a corresponding header. More than likely the phone only accepts the reboot NOTIFY requests from a server it has a current registration with (SIP REGISTER request).