Notfiy when extension is not registered

Hello,
I just noticed the following:

With older versions of Asterisk (chan_sip) if I would subscribe an extension that is not registered, my phone would show it as unavailable. Quite similar as if he would have a call.
With my Asterisk 18.15.1 (pjsip) it doesn’t, while notifys when the subscribed extension is busy or getting a call work as expected.

I tried to find out the difference and while I am not sure if I am looking at the right thing, I noticed that a notify for an unregistered extension in older Asterisk versions with chan_sip looks like this (extension 13 is not registered):

NOTIFY sip:12@192.168.1.105:5060;line=9v0c5jfr SIP/2.0
Via: SIP/2.0/UDP 192.168.1.211:5060;branch=z9hG4bK32aca4c8;rport
From: <sip:13@192.168.1.211>;tag=as695c7c00
To: <sip:12@192.168.1.211>;tag=8icw968fon
Contact: <sip:13@192.168.1.211>
Call-ID: c68e05668ba0-m2wf04q1fsly
CSeq: 102 NOTIFY
User-Agent: PBX
Max-Forwards: 70
Event: dialog
Content-Type: application/dialog-info+xml
Subscription-State: active
Content-Length: 201

<?xml version="1.0"?>
<dialog-info xmlns="urn:ietf:params:xml:ns:dialog-info" version="0" state="full" entity="sip:13@192.168.1.211">
<dialog id="13">
<state>confirmed</state>
</dialog>
</dialog-info>

While with pjsip it looks like this (extension 18 is NOT registered)

NOTIFY sip:10@192.168.1.100:15063 SIP/2.0
Via: SIP/2.0/UDP 192.168.1.253:54321;rport;branch=z9hG4bKPj56cbc372-137f-4eeb-a7c3-567d87833f0d
From: <sip:18@192.168.1.253;user=phone>;tag=30af072f-d537-44df-b4f8-7d5f3af67ac4
To: <sip:10@192.168.1.253>;tag=2af762c8
Contact: <sip:192.168.1.253:54321>
Call-ID: 047AB9C0-2B0EB9B4701F5D037A5A767D
CSeq: 16893 NOTIFY
Event: dialog
Subscription-State: terminated
Allow-Events: presence, dialog, message-summary, refer
Max-Forwards: 70
User-Agent: PBX
Content-Type: application/dialog-info+xml
Content-Length:   234

<?xml version="1.0" encoding="UTF-8"?>
<dialog-info xmlns="urn:ietf:params:xml:ns:dialog-info" version="0" state="full" entity="sip:18@192.168.1.253;user=phone">
 <dialog id="18">
  <state>terminated</state>
 </dialog>
</dialog-info>

It looks like this notify makes my phone (tested with different phones and softphones) think the extension is availabe, while with old chan_sip it turns red on the phone.

Is there something I can do to get the old behaviour?

I watched this issue a bit more and indeed the problem for me seems to be that older Asterisk with chan_sip would send periodically Notfiys with state “confirmed” (as in example above) for subscribed extensions that are not registered / unavailable.
While I am not sure if “confirmed” is the right thing to send here, it produced the desired behaviour - showing the subscribed extension unavailabe (red button for example) on phones and softphones.

With my Asterisk 18.15 and pjsip, it just sends “terminated”, which means extension is free and has no calls. This makes the phone show the subscribed extension available - which is not the case.

Example of Asterisk 18.15 with pjsip, extension 35 is subscribing extension 18 (which is not registered and not there at all)

<--- Received SIP request (729 bytes) from UDP:10.0.0.110:5060 --->
SUBSCRIBE sip:192.168.1.253:54321 SIP/2.0
Via: SIP/2.0/UDP 10.0.0.110:5060;branch=z9hG4bK-t7z60w24ccne;rport
From: <sip:35@192.168.1.253:54321>;tag=ztrrhf1d0s
To: <sip:18@192.168.1.253>;tag=bf6ed876-9866-4086-a4bb-6499fa49002b
Call-ID: 618a056674db-ziljt44n36gj
CSeq: 26 SUBSCRIBE
Max-Forwards: 70
User-Agent: snomD385/10.1.159.12
Contact: <sip:35@10.0.0.110:5060>;reg-id=1
Event: dialog
Accept: application/dialog-info+xml
Authorization: Digest username="35",realm="asterisk",nonce="xxxx",uri="sip:192.168.1.253:54321",qop=auth,nc=00000002,cnonce="63dbbe89",response="xxxx",opaque="1f6154de616a42e2",algorithm=MD5
Expires: 600
Content-Length: 0


<--- Transmitting SIP response (526 bytes) to UDP:10.0.0.110:5060 --->
SIP/2.0 200 OK
Via: SIP/2.0/UDP 10.0.0.110:5060;rport=5060;received=10.0.0.110;branch=z9hG4bK-t7z60w24ccne
Call-ID: 618a056674db-ziljt44n36gj
From: <sip:35@192.168.1.253>;tag=ztrrhf1d0s
To: <sip:18@192.168.1.253>;tag=bf6ed876-9866-4086-a4bb-6499fa49002b
CSeq: 26 SUBSCRIBE
Expires: 600
Contact: <sip:192.168.1.253:54321>
Allow: OPTIONS, REGISTER, SUBSCRIBE, NOTIFY, PUBLISH, INVITE, ACK, BYE, CANCEL, UPDATE, PRACK, MESSAGE, REFER
Supported: 100rel, timer, replaces, norefersub
Server: PBX
Content-Length:  0


<--- Transmitting SIP request (788 bytes) to UDP:10.0.0.110:5060 --->
NOTIFY sip:35@10.0.0.110:5060 SIP/2.0
Via: SIP/2.0/UDP 192.168.1.253:54321;rport;branch=z9hG4bKPj03149446-25fd-4821-b4d6-18f9360ddd6f
From: <sip:18@192.168.1.253>;tag=bf6ed876-9866-4086-a4bb-6499fa49002b
To: <sip:35@192.168.1.253>;tag=ztrrhf1d0s
Contact: <sip:192.168.1.253:54321>
Call-ID: 618a056674db-ziljt44n36gj
CSeq: 12141 NOTIFY
Event: dialog
Subscription-State: active;expires=599
Allow-Events: presence, dialog, message-summary, refer
Max-Forwards: 70
User-Agent: PBX
Content-Type: application/dialog-info+xml
Content-Length:   229

<?xml version="1.0" encoding="UTF-8"?>
<dialog-info xmlns="urn:ietf:params:xml:ns:dialog-info" version="1" state="full" entity="sip:18@192.168.1.253:54321">
 <dialog id="18">
  <state>terminated</state>
 </dialog>
</dialog-info>

<--- Received SIP response (344 bytes) from UDP:10.0.0.110:5060 --->
SIP/2.0 200 Ok
Via: SIP/2.0/UDP 192.168.1.253:54321;rport=54321;branch=z9hG4bKPj03149446-25fd-4821-b4d6-18f9360ddd6f
From: <sip:18@192.168.1.253>;tag=bf6ed876-9866-4086-a4bb-6499fa49002b
To: <sip:35@192.168.1.253>;tag=ztrrhf1d0s
Call-ID: 618a056674db-ziljt44n36gj
CSeq: 12141 NOTIFY
User-Agent: snomD385/10.1.159.12
Content-Length: 0

Both chan_sip and chan_pjsip use the same general logic[1] to determine what to place in the NOTIFY for that value, and both use “terminated” if the extension is unavailable.

I would suggest providing the hint configuration as well as the output of “core show hints” for both.

[1] asterisk/res/res_pjsip/presence_xml.c at master · asterisk/asterisk · GitHub

Thank you. Your pointer to the code showed me what’s the thing.
I must say that I didn’t notice the difference for really really long time (many years). Because usually my phones are all online :wink: Maybe this was changed already long time ago.

So my only possibility now to check old behaviour is an old VM I had on archive with Asterisk 1.2.40. Sorry for that. But at least I could see the difference here:

So while in the code of actual version (your link) I can see

	case AST_EXTENSION_UNAVAILABLE:
		statestring = "terminated";
		local_state = NOTIFY_CLOSED;
		pidfstate = "--";
		pidfnote = "Unavailable";
		break;

in the old version (file channels/chan_sip.c) it looks like this:

        case AST_EXTENSION_UNAVAILABLE:
                statestring = "confirmed";
                local_state = NOTIFY_CLOSED;
                pidfstate = "away";
                pidfnote = "Unavailable";
                break;

According to the commity history it was changed in Asterisk 1.4 in chan_sip over 17 years ago to “terminated”.

Thank you. Yeah, time flies…
I will think about it and maybe change it in source code and recompile by myself. Because with “terminated” I will never see on other devices if a phone is just simply plugged out.