sipsorcery-org / sipsorcery

A WebRTC, SIP and VoIP library for C# and .NET. Designed for real-time communications apps.
https://sipsorcery-org.github.io/sipsorcery
Other
1.42k stars 431 forks source link

P-Registrar-Error: Invalid CSeq number / NFON #1038

Open benspi opened 8 months ago

benspi commented 8 months ago

Hello, I ran into an issue that i cannot re-register to our cloud pbx. are there any suggestions to overcome this issue?

Registering... Outbound proxy address: udp:109.68.97.120:5060. Sucessfully Registered to PBX!

After a while....:

Temporary error registering! Registration failed with BadRequest. sip:KC1KL4V5@KC1.reg.cloud-cfg.com BadRequest SIP/2.0 400 Bad Request Via: SIP/2.0/UDP 192.168.0.10:5061;received=86.XXXX.197;branch=z9hG4bKe6e074e37c1343a685e8431f299e2853;rport=61808 To: sip:KC1KL4V5@KC1.reg.cloud-cfg.com;tag=d570-0cefe4cea546e72f9b2f9b00577b6839 From: sip:KC1KL4V5@KC1.reg.cloud-cfg.com;tag=NZWOIGANSL Call-ID: fdf6f1f3595a4b8d88fe1502ec4e133a CSeq: 2 REGISTER Contact: sip:KC1KL4V5@192.168.0.10:5061;expires=5;received="sip:86.XXXX:61808" Server: nfon2.0 Content-Length: 0 P-Registrar-Error: Invalid CSeq number

The Code:

static async Task Main(string[] args)
{
    //INIT Console and other Basics
    Console.ForegroundColor = ConsoleColor.Green;
    Console.WriteLine("Registering...");

    var sipTransport = new SIPTransport(false);
    sipTransport.EnableTraceLogs();
    sipTransport.DisableRetransmitSending = true; //DEBUG
    var udpChanel = new SIPUDPChannel(new IPEndPoint(IPAddress.Any, 5061));
    sipTransport.AddSIPChannel(udpChanel);

    //Register to PBX
    var proxy = await SIPDns.ResolveAsync(SIPURI.ParseSIPURI("sip:KC1.reg.cloud-cfg.com;transport=udp"), false, CancellationToken.None);
    Console.WriteLine($"Outbound proxy address: {proxy}.");

    var contactUri = new SIPURI("KC1KL4V5", $"{ IPAddress.Any}:0", null, SIPSchemesEnum.sip, SIPProtocolsEnum.udp);

    var regUserAgent = new SIPRegistrationUserAgent(sipTransport,
        proxy,
        SIPURI.ParseSIPURI("sip:KC1KL4V5@KC1.reg.cloud-cfg.com"),
        USERNAME,
        PASSWORD,
        "KC1.reg.cloud-cfg.com",
        "KC1.reg.cloud-cfg.com",
        contactUri,
        900,
        null);
    //var regUserAgent = new SIPRegistrationUserAgent(sipTransport, USERNAME, PASSWORD, SERVER, EXPIRY);

    regUserAgent.RegistrationFailed += RegUserAgent_RegistrationFailed;
    regUserAgent.RegistrationTemporaryFailure += RegUserAgent_RegistrationTemporaryFailure;
    regUserAgent.RegistrationSuccessful += RegUserAgent_RegistrationSuccessful;
    regUserAgent.RegistrationRemoved += RegUserAgent_RegistrationRemoved;

    regUserAgent.UserAgent = "Sip2Mail";
    regUserAgent.Start();``
sipsorcery commented 8 months ago

Do you have the log messages from the sipsorcery attempts?

Also, this isn't correct $"{IPAddress.Any}:0". The contact URI needs a port. Either leave the 0 off to use the default 5060/5061 port or specify a dedicated port. If you have a NAT on your network path you can also leave off the 0 and the SIP registrar server should be able to deal with it.