How to differentiate device offline status and no endpoints by response error code in Dial() execution?

Recently, we’ve migrated chan_sip to PJSIP(of Asterisk 18.2.2).

In chan_sip, we can differentiate device offline status(480/408) and no sippeers(404) by response error codes.

But in PJSIP, both are 404 error codes.

we checked the log of these types.

  1. Dial() to endpoint which is in DB(realtime ODBC) but offline status.
    -- Executing [1100000003@sc:1] Dial("PJSIP/421894210-00000013", "PJSIP/1100000003,Tt") in new stack
[2021-03-22 11:50:44] ERROR[4731]: res_pjsip.c:3938 ast_sip_create_dialog_uac: Endpoint '1100000003': Could not create dialog to invalid URI '1100000003'.  Is endpoint registered and reachable?
[2021-03-22 11:50:44] ERROR[4731]: chan_pjsip.c:2645 request: Failed to create outgoing session to endpoint '1100000003'
[2021-03-22 11:50:44] WARNING[4969][C-00000014]: app_dial.c:2596 dial_exec_full: Unable to create channel of type 'PJSIP' (cause 3 - No route to destination)
    -- No devices or endpoints to dial (technology/resource)
    -- Executing [1100000003@sc:2] Hangup("PJSIP/421894210-00000013", "") in new stack
  == Spawn extension (sc, 1100000003, 2) exited non-zero on 'PJSIP/421894210-00000013'
<--- Transmitting SIP response (447 bytes) to UDP:xxx.xxx.xxx.xxx:45605 --->
SIP/2.0 404 Not Found
Via: SIP/2.0/UDP 192.168.10.239:62971;rport=45605;received=xxx.xxx.xxx.xxx;branch=z9hG4bK-524287-1---b0cbae40797083e9
  1. Dial() to endpoint which is not in DB(realtime ODBC).
    -- Executing [1199999999@sc:1] Dial("PJSIP/421894210-00000015", "PJSIP/1199999999,Tt") in new stack
[2021-03-22 11:51:32] ERROR[4975]: chan_pjsip.c:2616 request: Unable to create PJSIP channel - endpoint '1199999999' was not found
[2021-03-22 11:51:32] WARNING[4979][C-00000016]: app_dial.c:2596 dial_exec_full: Unable to create channel of type 'PJSIP' (cause 3 - No route to destination)
    -- No devices or endpoints to dial (technology/resource)
    -- Executing [1199999999@sc:2] Hangup("PJSIP/421894210-00000015", "") in new stack
  == Spawn extension (sc, 1199999999, 2) exited non-zero on 'PJSIP/421894210-00000015'
<--- Transmitting SIP response (447 bytes) to UDP:xxx.xxx.xxx.xxx:45605 --->
SIP/2.0 404 Not Found
Via: SIP/2.0/UDP 192.168.10.239:62971;rport=45605;received=xxx.xxx.xxx.xxx;branch=z9hG4bK-524287-1---76e64da63e347fa3

extensions.conf is below

[sc]
exten => _11XXXXXXXX,1,Dial(PJSIP/${EXTEN},30,Tt)
exten => _11XXXXXXXX,2,hangup()

and endpoints are like this(realtime ODBC)

    ps_aors: (id: number, max_contacts: 10)
    ps_auths: (id: number, auth_type: "userpass", password: sip_password, username: number)
    ps_endpoints: (id: number, transport: "transport-udp", aors: number,
                                  auth: number, context: "sc", direct_media: "yes",
                                  disallow: "all", allow: "ulaw",
                                  rtp_symmetric: "yes", force_rport: "yes", rewrite_contact: "yes")

As you might see, log is a little bit different but the response is both 404. expected 480 or 408

I checked this page but I guess chan_sip and PJSIP responses the same error code.
https://wiki.asterisk.org/wiki/display/AST/Hangup+Cause+Mappings

Any solution to this problem?
thanks.

I guess this is a bug.
We’re going to use ARI to check endpoint existance instead of error code.

I agree it does appear to be a little buggy.

You might be able to work around it with some extra info from the Asterisk dial plan function PJSIP_CONTACT.

There are also cause code options available for Hangup() application.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.