Exchanging Device State Using PJSIP

Hello!

I’m trying to use this config: Exchanging Device and Mailbox State Using PJSIP - Asterisk Project - Asterisk Project Wiki

But Asterisks require authorization.

How can I disable this?

If you don’t set auth on an endpoint then it won’t challenge for authentication. If this isn’t happening, then your configuration may not be doing what you expect or the traffic not matching how you expect, in which case you’d need to provide the actual configuration along with SIP trace (pjsip set logger on).

PUBLISH appears only after ‘systemctl restart asterisk’. And I don’t see the ‘instanceX’ endpoint on both Asterisks

[global]
disable_multi_domain=yes
endpoint_identifier_order=header,ip,username
[instance2]
type=endpoint

[instance2-devicestate]
type=outbound-publish
server_uri=sip:instance1@10.0.0.7
event=asterisk-devicestate

[instance2-mwi]
type=outbound-publish
server_uri=sip:instance1@10.0.0.7
event=asterisk-mwi

[instance2]
type=inbound-publication
event_asterisk-devicestate=instance2
event_asterisk-mwi=instance2

[instance2]
type=asterisk-publication
devicestate_publish=instance2-devicestate
mailboxstate_publish=instance2-mwi
device_state=yes
mailbox_state=yes
[instance1]
type=endpoint

[instance1-devicestate]
type=outbound-publish
server_uri=sip:instance2@10.0.0.3
event=asterisk-devicestate

[instance1-mwi]
type=outbound-publish
server_uri=sip:instance2@10.0.0.3
event=asterisk-mwi

[instance1]
type=inbound-publication
event_asterisk-devicestate=instance1
event_asterisk-mwi=instance1

[instance1]
type=asterisk-publication
devicestate_publish=instance1-devicestate
mailboxstate_publish=instance1-mwi
device_state=yes
mailbox_state=yes

<--- Received SIP request (544 bytes) from UDP:10.0.0.3:5060 --->
PUBLISH sip:instance1@10.0.0.7 SIP/2.0
Via: SIP/2.0/UDP 10.0.0.3:5060;rport;branch=z9hG4bKPj89bf249f-ca28-48f8-8077-a03cf669a82a
From: <sip:instance1@10.0.0.7>;tag=74d30505-cc35-4cdd-9a65-3b428ce17c41
To: <sip:instance1@10.0.0.7>
Call-ID: d732f616-2bac-48ee-96c8-506c1870f0e1
CSeq: 38335 PUBLISH
Event: asterisk-devicestate
Expires: 3600
Max-Forwards: 70
User-Agent: P2SIP-A
Content-Type: application/json
Content-Length:   102

{"type":"devicestate","device":"PJSIP/volna","state":"INVALID","cachable":1,"eid":"96:00:01:66:0d:60"}
[Sep 28 09:41:32] NOTICE[9514]: res_pjsip/pjsip_distributor.c:676 log_failed_request: Request 'PUBLISH' from '<sip:instance1@10.0.0.7>' failed for '10.0.0.3:5060' (callid: d732f616-2bac-48ee-96c8-506c1870f0e1) - No matching endpoint found
<--- Transmitting SIP response (548 bytes) to UDP:10.0.0.3:5060 --->
SIP/2.0 401 Unauthorized
Via: SIP/2.0/UDP 10.0.0.3:5060;rport=5060;received=10.0.0.3;branch=z9hG4bKPj89bf249f-ca28-48f8-8077-a03cf669a82a
Call-ID: d732f616-2bac-48ee-96c8-506c1870f0e1
From: <sip:instance1@10.0.0.7>;tag=74d30505-cc35-4cdd-9a65-3b428ce17c41
To: <sip:instance1@10.0.0.7>;tag=z9hG4bKPj89bf249f-ca28-48f8-8077-a03cf669a82a
CSeq: 38335 PUBLISH
WWW-Authenticate: Digest realm="p2sipagent",nonce="1664358092/c9227d65b6da9f4899e21cb5b0ad1aa6",opaque="42996469746582e4",algorithm=MD5,qop="auth"
Server: P2SIP-A
Content-Length:  0


<--- Received SIP request (544 bytes) from UDP:10.0.0.3:5060 --->
PUBLISH sip:instance1@10.0.0.7 SIP/2.0
Via: SIP/2.0/UDP 10.0.0.3:5060;rport;branch=z9hG4bKPj89bf249f-ca28-48f8-8077-a03cf669a82a
From: <sip:instance1@10.0.0.7>;tag=74d30505-cc35-4cdd-9a65-3b428ce17c41
To: <sip:instance1@10.0.0.7>
Call-ID: d732f616-2bac-48ee-96c8-506c1870f0e1
CSeq: 38335 PUBLISH
Event: asterisk-devicestate
Expires: 3600
Max-Forwards: 70
User-Agent: P2SIP-A
Content-Type: application/json
Content-Length:   102

{"type":"devicestate","device":"PJSIP/volna","state":"INVALID","cachable":1,"eid":"96:00:01:66:0d:60"}
[Sep 28 09:41:33] NOTICE[9514]: res_pjsip/pjsip_distributor.c:676 log_failed_request: Request 'PUBLISH' from '<sip:instance1@10.0.0.7>' failed for '10.0.0.3:5060' (callid: d732f616-2bac-48ee-96c8-506c1870f0e1) - No matching endpoint found
<--- Transmitting SIP response (548 bytes) to UDP:10.0.0.3:5060 --->
SIP/2.0 401 Unauthorized
Via: SIP/2.0/UDP 10.0.0.3:5060;rport=5060;received=10.0.0.3;branch=z9hG4bKPj89bf249f-ca28-48f8-8077-a03cf669a82a
Call-ID: d732f616-2bac-48ee-96c8-506c1870f0e1
From: <sip:instance1@10.0.0.7>;tag=74d30505-cc35-4cdd-9a65-3b428ce17c41
To: <sip:instance1@10.0.0.7>;tag=z9hG4bKPj89bf249f-ca28-48f8-8077-a03cf669a82a
CSeq: 38335 PUBLISH
WWW-Authenticate: Digest realm="p2sipagent",nonce="1664358093/317a418d52842127c5c756616184e502",opaque="0a3609872364a41b",algorithm=MD5,qop="auth"
Server: P2SIP-A
Content-Length:  0


<--- Received SIP request (544 bytes) from UDP:10.0.0.3:5060 --->
PUBLISH sip:instance1@10.0.0.7 SIP/2.0
Via: SIP/2.0/UDP 10.0.0.3:5060;rport;branch=z9hG4bKPj89bf249f-ca28-48f8-8077-a03cf669a82a
From: <sip:instance1@10.0.0.7>;tag=74d30505-cc35-4cdd-9a65-3b428ce17c41
To: <sip:instance1@10.0.0.7>
Call-ID: d732f616-2bac-48ee-96c8-506c1870f0e1
CSeq: 38335 PUBLISH
Event: asterisk-devicestate
Expires: 3600
Max-Forwards: 70
User-Agent: P2SIP-A
Content-Type: application/json
Content-Length:   102

{"type":"devicestate","device":"PJSIP/volna","state":"INVALID","cachable":1,"eid":"96:00:01:66:0d:60"}
[Sep 28 09:41:33] NOTICE[9514]: res_pjsip/pjsip_distributor.c:676 log_failed_request: Request 'PUBLISH' from '<sip:instance1@10.0.0.7>' failed for '10.0.0.3:5060' (callid: d732f616-2bac-48ee-96c8-506c1870f0e1) - No matching endpoint found
<--- Transmitting SIP response (548 bytes) to UDP:10.0.0.3:5060 --->
SIP/2.0 401 Unauthorized
Via: SIP/2.0/UDP 10.0.0.3:5060;rport=5060;received=10.0.0.3;branch=z9hG4bKPj89bf249f-ca28-48f8-8077-a03cf669a82a
Call-ID: d732f616-2bac-48ee-96c8-506c1870f0e1
From: <sip:instance1@10.0.0.7>;tag=74d30505-cc35-4cdd-9a65-3b428ce17c41
To: <sip:instance1@10.0.0.7>;tag=z9hG4bKPj89bf249f-ca28-48f8-8077-a03cf669a82a
CSeq: 38335 PUBLISH
WWW-Authenticate: Digest realm="p2sipagent",nonce="1664358093/317a418d52842127c5c756616184e502",opaque="4a05cf1d13dd8c6b",algorithm=MD5,qop="auth"
Server: P2SIP-A
Content-Length:  0


<--- Received SIP request (525 bytes) from UDP:10.0.0.3:5060 --->
PUBLISH sip:instance1@10.0.0.7 SIP/2.0
Via: SIP/2.0/UDP 10.0.0.3:5060;rport;branch=z9hG4bKPj2f4541c6-d874-4b8e-9787-3c520200f997
From: <sip:instance1@10.0.0.7>;tag=cab02cf2-7c13-4959-b6b3-66af545aeedf
To: <sip:instance1@10.0.0.7>
Call-ID: 48425c4e-2203-454b-b8ec-909840324293
CSeq: 44124 PUBLISH
Event: asterisk-mwi
Expires: 3600
Max-Forwards: 70
User-Agent: P2SIP-A
Content-Type: application/json
Content-Length:    91

{"type":"mailboxstate","uniqueid":"1234@default","old":0,"new":0,"eid":"96:00:01:66:0d:60"}
[Sep 28 09:41:34] NOTICE[9514]: res_pjsip/pjsip_distributor.c:676 log_failed_request: Request 'PUBLISH' from '<sip:instance1@10.0.0.7>' failed for '10.0.0.3:5060' (callid: 48425c4e-2203-454b-b8ec-909840324293) - No matching endpoint found
<--- Transmitting SIP response (548 bytes) to UDP:10.0.0.3:5060 --->
SIP/2.0 401 Unauthorized
Via: SIP/2.0/UDP 10.0.0.3:5060;rport=5060;received=10.0.0.3;branch=z9hG4bKPj2f4541c6-d874-4b8e-9787-3c520200f997
Call-ID: 48425c4e-2203-454b-b8ec-909840324293
From: <sip:instance1@10.0.0.7>;tag=cab02cf2-7c13-4959-b6b3-66af545aeedf
To: <sip:instance1@10.0.0.7>;tag=z9hG4bKPj2f4541c6-d874-4b8e-9787-3c520200f997
CSeq: 44124 PUBLISH
WWW-Authenticate: Digest realm="p2sipagent",nonce="1664358094/200e6cc4cfda83f9b52dc529961a319b",opaque="40720c2e12906b98",algorithm=MD5,qop="auth"
Server: P2SIP-A
Content-Length:  0


<--- Received SIP request (525 bytes) from UDP:10.0.0.3:5060 --->
PUBLISH sip:instance1@10.0.0.7 SIP/2.0
Via: SIP/2.0/UDP 10.0.0.3:5060;rport;branch=z9hG4bKPj2f4541c6-d874-4b8e-9787-3c520200f997
From: <sip:instance1@10.0.0.7>;tag=cab02cf2-7c13-4959-b6b3-66af545aeedf
To: <sip:instance1@10.0.0.7>
Call-ID: 48425c4e-2203-454b-b8ec-909840324293
CSeq: 44124 PUBLISH
Event: asterisk-mwi
Expires: 3600
Max-Forwards: 70
User-Agent: P2SIP-A
Content-Type: application/json
Content-Length:    91

{"type":"mailboxstate","uniqueid":"1234@default","old":0,"new":0,"eid":"96:00:01:66:0d:60"}
[Sep 28 09:41:35] NOTICE[9514]: res_pjsip/pjsip_distributor.c:676 log_failed_request: Request 'PUBLISH' from '<sip:instance1@10.0.0.7>' failed for '10.0.0.3:5060' (callid: 48425c4e-2203-454b-b8ec-909840324293) - No matching endpoint found
<--- Transmitting SIP response (548 bytes) to UDP:10.0.0.3:5060 --->
SIP/2.0 401 Unauthorized
Via: SIP/2.0/UDP 10.0.0.3:5060;rport=5060;received=10.0.0.3;branch=z9hG4bKPj2f4541c6-d874-4b8e-9787-3c520200f997
Call-ID: 48425c4e-2203-454b-b8ec-909840324293
From: <sip:instance1@10.0.0.7>;tag=cab02cf2-7c13-4959-b6b3-66af545aeedf
To: <sip:instance1@10.0.0.7>;tag=z9hG4bKPj2f4541c6-d874-4b8e-9787-3c520200f997
CSeq: 44124 PUBLISH
WWW-Authenticate: Digest realm="p2sipagent",nonce="1664358095/d94fbd5a2332af5bcddb6c6cc55c4901",opaque="61ae2d7709d27bbb",algorithm=MD5,qop="auth"
Server: P2SIP-A
Content-Length:  0


<--- Received SIP request (544 bytes) from UDP:10.0.0.3:5060 --->
PUBLISH sip:instance1@10.0.0.7 SIP/2.0
Via: SIP/2.0/UDP 10.0.0.3:5060;rport;branch=z9hG4bKPj89bf249f-ca28-48f8-8077-a03cf669a82a
From: <sip:instance1@10.0.0.7>;tag=74d30505-cc35-4cdd-9a65-3b428ce17c41
To: <sip:instance1@10.0.0.7>
Call-ID: d732f616-2bac-48ee-96c8-506c1870f0e1
CSeq: 38335 PUBLISH
Event: asterisk-devicestate
Expires: 3600
Max-Forwards: 70
User-Agent: P2SIP-A
Content-Type: application/json
Content-Length:   102

{"type":"devicestate","device":"PJSIP/volna","state":"INVALID","cachable":1,"eid":"96:00:01:66:0d:60"}
[Sep 28 09:41:36] NOTICE[9514]: res_pjsip/pjsip_distributor.c:676 log_failed_request: Request 'PUBLISH' from '<sip:instance1@10.0.0.7>' failed for '10.0.0.3:5060' (callid: d732f616-2bac-48ee-96c8-506c1870f0e1) - No matching endpoint found
<--- Transmitting SIP response (548 bytes) to UDP:10.0.0.3:5060 --->
SIP/2.0 401 Unauthorized
Via: SIP/2.0/UDP 10.0.0.3:5060;rport=5060;received=10.0.0.3;branch=z9hG4bKPj89bf249f-ca28-48f8-8077-a03cf669a82a
Call-ID: d732f616-2bac-48ee-96c8-506c1870f0e1
From: <sip:instance1@10.0.0.7>;tag=74d30505-cc35-4cdd-9a65-3b428ce17c41
To: <sip:instance1@10.0.0.7>;tag=z9hG4bKPj89bf249f-ca28-48f8-8077-a03cf669a82a
CSeq: 38335 PUBLISH
WWW-Authenticate: Digest realm="p2sipagent",nonce="1664358096/84be85ede771539bcac57a517e5f2062",opaque="147b11e17bd4c556",algorithm=MD5,qop="auth"
Server: P2SIP-A
Content-Length:  0


<--- Received SIP request (525 bytes) from UDP:10.0.0.3:5060 --->
PUBLISH sip:instance1@10.0.0.7 SIP/2.0
Via: SIP/2.0/UDP 10.0.0.3:5060;rport;branch=z9hG4bKPj2f4541c6-d874-4b8e-9787-3c520200f997
From: <sip:instance1@10.0.0.7>;tag=cab02cf2-7c13-4959-b6b3-66af545aeedf
To: <sip:instance1@10.0.0.7>
Call-ID: 48425c4e-2203-454b-b8ec-909840324293
CSeq: 44124 PUBLISH
Event: asterisk-mwi
Expires: 3600
Max-Forwards: 70
User-Agent: P2SIP-A
Content-Type: application/json
Content-Length:    91

{"type":"mailboxstate","uniqueid":"1234@default","old":0,"new":0,"eid":"96:00:01:66:0d:60"}
[Sep 28 09:41:36] NOTICE[9514]: res_pjsip/pjsip_distributor.c:676 log_failed_request: Request 'PUBLISH' from '<sip:instance1@10.0.0.7>' failed for '10.0.0.3:5060' (callid: 48425c4e-2203-454b-b8ec-909840324293) - No matching endpoint found
<--- Transmitting SIP response (548 bytes) to UDP:10.0.0.3:5060 --->
SIP/2.0 401 Unauthorized
Via: SIP/2.0/UDP 10.0.0.3:5060;rport=5060;received=10.0.0.3;branch=z9hG4bKPj2f4541c6-d874-4b8e-9787-3c520200f997
Call-ID: 48425c4e-2203-454b-b8ec-909840324293
From: <sip:instance1@10.0.0.7>;tag=cab02cf2-7c13-4959-b6b3-66af545aeedf
To: <sip:instance1@10.0.0.7>;tag=z9hG4bKPj2f4541c6-d874-4b8e-9787-3c520200f997
CSeq: 44124 PUBLISH
WWW-Authenticate: Digest realm="p2sipagent",nonce="1664358096/84be85ede771539bcac57a517e5f2062",opaque="300d376528f6e209",algorithm=MD5,qop="auth"
Server: P2SIP-A
Content-Length:  0

Is this an existing system or something that has prior configuration? What is the output of /etc/asterisk/sorcery.conf? Are there any log messages at startup complaining about the endpoint configuration?

[res_pjsip]
endpoint/cache = memory_cache,maximum_objects=200,expire_on_reload=yes,object_lifetime_maximum=3600
endpoint=realtime,ps_endpoints
auth/cache = memory_cache,maximum_objects=200,expire_on_reload=yes,object_lifetime_maximum=3600
auth=realtime,ps_auths
aor/cache = memory_cache,maximum_objects=200,expire_on_reload=yes,object_lifetime_maximum=3600
aor=realtime,ps_aors
;domain_alias=realtime,ps_domain_aliases
contact/cache = memory_cache,maximum_objects=200,expire_on_reload=yes,object_lifetime_maximum=400
contact=realtime,ps_contacts

;[res_pjsip_endpoint_identifier_ip]
;identify/cache = memory_cache,maximum_objects=200,expire_on_reload=yes,object_lifetime_maximum=3600
;identify=realtime,ps_endpoint_id_ips

;[res_pjsip_outbound_publish]
;outbound-publish=realtime,ps_outbound_publishes

;[res_pjsip_pubsub]
;inbound-publication=realtime,ps_inbound_publications

[res_pjsip_publish_asterisk]
asterisk-publication=realtime,ps_asterisk_publications

Your endpoints are configured in realtime. You can’t configure them in pjsip.conf

Can I set it up to be used together (realtime and config)

You’d add:

endpoint=config,pjsip.conf,criteria=type=endpoint

After the realtime entry in sorcery.conf.

1 Like

Thanks!

It’s working!

Now I would like to add this config into Realtime (DB). But It’s not working again )

sorcery.conf:

[res_pjsip]
endpoint/cache = memory_cache,maximum_objects=200,expire_on_reload=yes,object_lifetime_maximum=3600
endpoint=realtime,ps_endpoints
endpoint=config,pjsip.conf,criteria=type=endpoint

auth/cache = memory_cache,maximum_objects=200,expire_on_reload=yes,object_lifetime_maximum=3600
auth=realtime,ps_auths

aor/cache = memory_cache,maximum_objects=200,expire_on_reload=yes,object_lifetime_maximum=3600
aor=realtime,ps_aors

;domain_alias=realtime,ps_domain_aliases
contact/cache = memory_cache,maximum_objects=200,expire_on_reload=yes,object_lifetime_maximum=400
contact=realtime,ps_contacts

;[res_pjsip_endpoint_identifier_ip]
;identify/cache = memory_cache,maximum_objects=200,expire_on_reload=yes,object_lifetime_maximum=3600
;identify=realtime,ps_endpoint_id_ips

[res_pjsip_outbound_publish]
outbound-publish/cache = memory_cache
outbound-publish=realtime,ps_outbound_publishes

[res_pjsip_pubsub]
inbound-publication/cache = memory_cache
inbound-publication=realtime,ps_inbound_publications

[res_pjsip_publish_asterisk]
asterisk-publication/cache = memory_cache
asterisk-publication=realtime,ps_asterisk_publications

Lines in the DB:

MariaDB [asterisk]> select * from ps_outbound_publishes\G
*************************** 1. row ***************************
               id: node-01
       expiration: NULL
    outbound_auth: NULL
   outbound_proxy: NULL
       server_uri: sip:node-01@10.0.0.3
         from_uri: NULL
           to_uri: NULL
            event: asterisk-devicestate
max_auth_attempts: NULL
        transport: NULL
       multi_user: NULL
            @body: NULL
         @context: NULL
           @exten: NULL
*************************** 2. row ***************************
               id: node-02
       expiration: NULL
    outbound_auth: NULL
   outbound_proxy: NULL
       server_uri: sip:node-02@10.0.0.7
         from_uri: NULL
           to_uri: NULL
            event: asterisk-devicestate
max_auth_attempts: NULL
        transport: NULL
       multi_user: NULL
            @body: NULL
         @context: NULL
           @exten: NULL
2 rows in set (0.01 sec)

MariaDB [asterisk]> select * from ps_inbound_publications\G
*************************** 1. row ***************************
                        id: node-01
                  endpoint: NULL
event_asterisk-devicestate: node-01
        event_asterisk-mwi: NULL
*************************** 2. row ***************************
                        id: node-02
                  endpoint: NULL
event_asterisk-devicestate: node-02
        event_asterisk-mwi: NULL
2 rows in set (0.00 sec)

MariaDB [asterisk]> select * from ps_asterisk_publications\G
*************************** 1. row ***************************
                  id: node-01
 devicestate_publish: node-01
mailboxstate_publish: NULL
        device_state: yes
 device_state_filter: NULL
       mailbox_state: NULL
mailbox_state_filter: NULL
*************************** 2. row ***************************
                  id: node-02
 devicestate_publish: node-02
mailboxstate_publish: NULL
        device_state: yes
 device_state_filter: NULL
       mailbox_state: NULL
mailbox_state_filter: NULL
2 rows in set (0.00 sec)

I haven’t tested any of the publication stuff in realtime, 'nor do I know if it works there.

It’s working in Realtime (i had the wrong extconfig.conf)! But both Asterisk servers get their config and this creates a loop (PUBLISH to itself). Is there some way to not load their settings (only each other)?

Use separate tables? There is no capability built into Asterisk itself to share tables but only have certain records returned for it. Any such capability would be from the database or some other mechanism.

Or separate views on the same table?

Thanks!

One more question ) Why does the cli-command dislpays only this:

node-01*CLI> sorcery memory cache dump res_pjsip/
res_pjsip/aor       res_pjsip/auth      res_pjsip/contact   res_pjsip/endpoint

although my config is:

[res_pjsip_outbound_publish]
outbound-publish/cache = memory_cache,maximum_objects=200,expire_on_reload=yes,object_lifetime_maximum=3600
outbound-publish=realtime,ps_outbound_publishes

[res_pjsip_pubsub]
inbound-publication/cache = memory_cache,maximum_objects=200,expire_on_reload=yes,object_lifetime_maximum=3600
inbound-publication=realtime,ps_inbound_publications

[res_pjsip_publish_asterisk]
asterisk-publication/cache = memory_cache,maximum_objects=200,expire_on_reload=yes,object_lifetime_maximum=3600
asterisk-publication=realtime,ps_asterisk_publications

Probably because those aren’t in the res_pjsip module, while you are dumping only the res_pjsip module.

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