Reboot phone using Notify

Please post requests related to the sipsorcery library to the GitHub repo https://github.com/sipsorcery/sipsorcery/issues.
Locked
VoIPTools
Posts: 3
Joined: Wed Dec 21, 2016 11:39 pm

Reboot phone using Notify

Post by VoIPTools » Thu Dec 22, 2016 1:18 am

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?

Aaron
Site Admin
Posts: 4652
Joined: Thu Jul 12, 2007 12:13 am

Re: Reboot phone using Notify

Post by Aaron » Thu Dec 22, 2016 5:11 am

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.

VoIPTools
Posts: 3
Joined: Wed Dec 21, 2016 11:39 pm

Re: Reboot phone using Notify

Post by VoIPTools » Fri Dec 23, 2016 1:59 pm

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.

Aaron
Site Admin
Posts: 4652
Joined: Thu Jul 12, 2007 12:13 am

Re: Reboot phone using Notify

Post by Aaron » Fri Jan 06, 2017 11:03 pm

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();
            }
        }
    }
}

VoIPTools
Posts: 3
Joined: Wed Dec 21, 2016 11:39 pm

Re: Reboot phone using Notify

Post by VoIPTools » Sat Jan 07, 2017 4:12 pm

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.

Aaron
Site Admin
Posts: 4652
Joined: Thu Jul 12, 2007 12:13 am

Re: Reboot phone using Notify

Post by Aaron » Tue Jan 10, 2017 7:12 am

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).

Locked