ATA Linksys SPA3102 pjsip trunk and caller id

Hello, community.

I have an old Linksys SPA3102 (1FXO, 1 FXS) installed and working.

I´ve managed to configure one pjsip trunk in FreePBX (15.0.16.61) in order to receive and make calls through the FXO port.

To get it working, I had to set the pjsip trunk like this:

Username: …
Secret:: …
Authentication: Outbound
Registration: Receive

And then I set Register: yes in the PSTN Line tab in the SPA configuration, along with the same username and secret set in the trunk, using the FreePBX IP address in the Proxy setting (192.168.10.207:5060).

I could receive calls just fine.

Then I turned on the option to enable caller id in the SPA (PSTN CID For VoIP CID: yes) and the errors bellow began to pop up, preventing inbound calls from the outside to get in:

(Numbers omitted for privacy reasons)

[2020-07-05 18:22:33] NOTICE[10425]: res_pjsip/pjsip_distributor.c:676 log_failed_request: Request 'INVITE' from '<sip:[email protected]>' failed for '192.168.10.3:5061' (callid: [email protected]) - No matching endpoint found
[2020-07-05 18:22:33] NOTICE[10425]: res_pjsip/pjsip_distributor.c:676 log_failed_request: Request 'INVITE' from '<sip:[email protected]>' failed for '192.168.10.3:5061' (callid: [email protected]) - No matching endpoint found
[2020-07-05 18:22:33] NOTICE[10425]: res_pjsip/pjsip_distributor.c:676 log_failed_request: Request 'INVITE' from '<sip:[email protected]>' failed for '192.168.10.3:5061' (callid: [email protected]) - Failed to authenticate
[2020-07-05 18:22:33] NOTICE[10425]: res_pjsip/pjsip_distributor.c:676 log_failed_request: Request 'INVITE' from '<sip:[email protected]>' failed for '192.168.10.3:5061' (callid: [email protected]) - No matching endpoint found
[2020-07-05 18:22:33] NOTICE[10425]: res_pjsip/pjsip_distributor.c:676 log_failed_request: Request 'INVITE' from '<sip:[email protected]>' failed for '192.168.10.3:5061' (callid: [email protected]) - Failed to authenticate

If I turn on “Allow Anonymous Inbound SIP Calls” in Settings > Asterisk SIP Settings", then the inbound call goes through, but something strange starts to happen: the call cannot be picked up by the extension in the first try. You have to pick up, then it seems to drop, then you put down the handset to hangup and pickup again. Really weird.

I´ve read in this post it is possible to completely remove authentication and registration from the trunk and set the SPA IP address as a “Match (Permit)” in the Advanced pjsip trunk options, and then also remove registration from the SPA (Register: no). If I do that everything works as expected. But I guess that would be insecure in some way.

So is it possible to make my SPA “trusted” by FreePBX so the inbound calls can get in without any errors or warnings, leaving authentication and registration on?

Thanks a lot.

As long as the spa and the freepbx are on the same network, it shouldn’t matter security wise.

Hello, @arielgrin. Anyway, it would be nice to understand what is going on and why the “no matching endpoin found” error is raised, so it could be fixed for any situation. If you have any pointers, I´d appreciate. Thanks a lot for your reply!

It seems odd that the SPA’s PSTN Line registration wants the pbx on the receiving end, but that very well may be correct. Still, have you verified that there are no issues during the registration, by looking at a packet capture. Also, can you describe the Inbound Route(s) you have set up for that trunk? For example, do you have a catchall route(Any DID) or a route that would match that X’d out number?

pjsip does not play well with devices that have both extensions and trunks at the same IP address. Unlike chan_sip, it does not take the remote port number into account when identifying the endpoint. The choices are IP (FXS and FXO conflict), username (won’t work with caller ID because SPA can only send it in the From header), header (not applicable here), and auth_username.

The latter should work fine and indeed one credible poster got it working, but he unfortunately did not post the recipe for his secret sauce.

Also (but not a problem), the SPA is not a registrar; so either it registers to the PBX, or its IP address is configured statically in the trunk.

Sorry that this is incomplete, but unfortunately once someone gets their problem solved, you often never hear from them again.

2 Likes

Hello, @wmoon, and thanks for your input.

The registration process seems to be ok. The LED in the SPA regarding the PSTN line lights up right away.

Here is the output from the SPA debug server:

Jul  8 19:23:52 192.168.10.3
Jul  8 19:23:52 192.168.10.3  [1]<<192.168.10.207:5060(423)
Jul  8 19:23:52 192.168.10.3  [1]<<192.168.10.207:5060(423)
Jul  8 19:23:52 192.168.10.3 SIP/2.0 200 OK#015#012Via: SIP/2.0/UDP 192.168.10.3:5060;rport=5060;received=192.168.10.3;branch=z9hG4bK-fd16b031#015#012Call-ID: [email protected]#015#012From: <sip:[email protected]>;tag=5bf5750a713a329do1#015#012To: <sip:[email protected]>;tag=z9hG4bK-fd16b031#015#012CSeq: 1637 REGISTER#015#012Date: Wed, 08 Jul 2020 22:23:52 GMT#015#012Contact: <sip:[email protected]:5060>;expires=3599#015#012Server: FPBX-15.0.16.61(16.9.0)#015#012Content-Length:  0#015#012#015
Jul  8 19:23:52 192.168.10.3
Jul  8 19:23:52 192.168.10.3
Jul  8 19:23:52 192.168.10.3  [1]RegOK. NextReg in 3570 (0)
Jul  8 19:23:52 192.168.10.3 AUD: Stop PSTN Tone
Jul  8 19:23:52 192.168.10.3  [1]<<192.168.10.207:5060(430)
Jul  8 19:23:52 192.168.10.3  [1]<<192.168.10.207:5060(430)
Jul  8 19:23:52 192.168.10.3
Jul  8 19:23:52 192.168.10.3
Jul  8 19:23:52 192.168.10.3  [1]->192.168.10.207:5060(455)
Jul  8 19:23:52 192.168.10.3  [1]->192.168.10.207:5060(455)
Jul  8 19:23:52 192.168.10.3 SIP/2.0 200 OK#015#012To: <sip:[email protected]>;tag=edf4f34edda52929i1#015#012From: <sip:[email protected]>;tag=304a61b0-8ff1-4905-a12e-dfb58bfa1664#015#012Call-ID: 8e3bde99-aae2-4ed6-9f3a-e3f2a61d0dc9#015#012CSeq: 56954 OPTIONS#015#012Via: SIP/2.0/UDP 192.168.10.207:5060;branch=z9hG4bKPj1285d738-ff78-4f19-bd66-93f03bd8c448#015#012Server: Linksys/SPA3102-5.2.13(GW002)#015#012Content-Length: 0#015#012Allow: ACK, BYE, CANCEL, INFO, INVITE, NOTIFY, OPTIONS, REFER#015#012Supported: x-sipura, replaces#015#012#015
Jul  8 19:23:52 192.168.10.3
Jul  8 19:23:52 192.168.10.3
Jul  8 19:23:52 192.168.10.3  [0]RegOK. NextReg in 3570 (1)
Jul  8 19:23:59 192.168.10.3 IDBG: st--995
Jul  8 19:24:00 192.168.10.3 fs: 11817:11890:65536
Jul  8 19:24:00 192.168.10.3 fls: af:1:0:0
Jul  8 19:24:00 192.168.10.3 fbr: 0:3000:3000:03f44:0016:0015:5.2.13(GW002)
Jul  8 19:24:00 192.168.10.3 fhs: 01:0:0003:upg:app:2:3.2.6(GWa)
Jul  8 19:24:00 192.168.10.3 fhs: 02:0:0004:upg:app:0:5.1.5(GWa)
Jul  8 19:24:00 192.168.10.3 fhs: 03:0:0005:upg:app:1:5.1.5(GWa)
Jul  8 19:24:00 192.168.10.3 fhs: 04:0:0006:upg:app:2:5.1.5(GWa)
Jul  8 19:24:00 192.168.10.3 fhs: 05:0:0007:upg:app:0:5.1.7(GW)
Jul  8 19:24:00 192.168.10.3 fhs: 06:0:0008:upg:app:1:5.1.7(GW)
Jul  8 19:24:00 192.168.10.3 fhs: 07:0:0009:upg:app:2:5.1.7(GW)
Jul  8 19:24:00 192.168.10.3 fhs: 08:0:000a:upg:app:0:5.1.7(GW)
Jul  8 19:24:00 192.168.10.3 fhs: 09:0:000b:upg:app:1:5.1.7(GW)
Jul  8 19:24:00 192.168.10.3 fhs: 0a:0:000c:upg:app:2:5.1.7(GW)
Jul  8 19:24:00 192.168.10.3 fhs: 0b:0:000d:upg:app:0:5.1.10(GW)
Jul  8 19:24:00 192.168.10.3 fhs: 0c:0:000e:upg:app:1:5.1.10(GW)
Jul  8 19:24:00 192.168.10.3 fhs: 0d:0:000f:upg:app:2:5.1.10(GW)
Jul  8 19:24:00 192.168.10.3 fhs: 0e:0:0010:upg:app:0:5.2.13(GW002)
Jul  8 19:24:00 192.168.10.3 fhs: 0f:0:0011:upg:app:1:5.2.13(GW002)
Jul  8 19:24:00 192.168.10.3 fhs: 10:0:0012:upg:app:2:5.2.13(GW002)
Jul  8 19:24:00 192.168.10.3 PLKUP: 2048, 768, 11, 1.5
Jul  8 19:24:00 192.168.10.3 fu: 0:3f6b, 0003 0001
Jul  8 19:24:52 192.168.10.3  [1]<<192.168.10.207:5060(430)
Jul  8 19:24:52 192.168.10.3  [1]<<192.168.10.207:5060(430)
Jul  8 19:24:52 192.168.10.3

And here is the output in the asterisk -rvvv console:

freepbx*CLI>
    -- Added contact 'sip:[email protected]:5060' to AOR 'pstn' with expiration of 3600 seconds
  == Endpoint pstn is now Reachable
    -- Contact pstn/sip:[email protected]:5060 is now Reachable.  RTT: 10.610 msec
freepbx*CLI>

These are the trunk settings:

The inbound route (the only one in the system) is as follows:

And the SPA dial plan is like this:

Sometimes I get a “no service message” when I try to call the PSTN Line:

freepbx*CLI>
    -- Added contact 'sip:[email protected]:5060' to AOR 'pstn' with expiration of 3600 seconds
  == Endpoint pstn is now Reachable
    -- Contact pstn/sip:[email protected]:5060 is now Reachable.  RTT: 10.610 msec
  == Setting global variable 'SIPDOMAIN' to '192.168.10.207'
    -- Executing [1125386356@from-sip-external:1] NoOp("PJSIP/anonymous-00000015", "Received incoming SIP connection from unknown peer to 1125386356") in new stack
    -- Executing [1125386356@from-sip-external:2] Set("PJSIP/anonymous-00000015", "DID=1125386356") in new stack
    -- Executing [1125386356@from-sip-external:3] Goto("PJSIP/anonymous-00000015", "s,1") in new stack
    -- Goto (from-sip-external,s,1)
    -- Executing [s@from-sip-external:1] GotoIf("PJSIP/anonymous-00000015", "1?setlanguage:checkanon") in new stack
    -- Goto (from-sip-external,s,2)
    -- Executing [s@from-sip-external:2] Set("PJSIP/anonymous-00000015", "CHANNEL(language)=en") in new stack
    -- Executing [s@from-sip-external:3] GotoIf("PJSIP/anonymous-00000015", "1?noanonymous") in new stack
    -- Goto (from-sip-external,s,5)
    -- Executing [s@from-sip-external:5] Set("PJSIP/anonymous-00000015", "TIMEOUT(absolute)=15") in new stack
    -- Channel will hangup at 2020-07-08 22:31:55.006 UTC.
    -- Executing [s@from-sip-external:6] Set("PJSIP/anonymous-00000015", "receveip=pjsip,remote_addr") in new stack
    -- Executing [s@from-sip-external:7] Log("PJSIP/anonymous-00000015", "WARNING,"Rejecting unknown SIP connection from 192.168.10.3:5060"") in new stack
[2020-07-08 22:31:40] WARNING[5401][C-0000001a]: Ext. s:7 @ from-sip-external: "Rejecting unknown SIP connection from 192.168.10.3:5060"
    -- Executing [s@from-sip-external:8] Answer("PJSIP/anonymous-00000015", "") in new stack
[2020-07-08 22:31:40] WARNING[5401][C-0000001a]: translate.c:488 ast_translator_build_path: No translator path: (starting codec is not valid)
[2020-07-08 22:31:40] WARNING[5401][C-0000001a]: translate.c:488 ast_translator_build_path: No translator path: (starting codec is not valid)
    -- Executing [s@from-sip-external:9] Wait("PJSIP/anonymous-00000015", "2") in new stack
[2020-07-08 22:31:42] WARNING[5401][C-0000001a]: channel.c:5688 set_format: Unable to find a codec translation path: (g723) -> (ulaw)
[2020-07-08 22:31:42] ERROR[5401][C-0000001a]: channel.c:8184 ast_channel_stop_silence_generator: Could not return write format to its original state
    -- Executing [s@from-sip-external:10] Playback("PJSIP/anonymous-00000015", "ss-noservice") in new stack
    -- <PJSIP/anonymous-00000015> Playing 'ss-noservice.ulaw' (language 'en')
    -- Executing [s@from-sip-external:11] PlayTones("PJSIP/anonymous-00000015", "congestion") in new stack
    -- Executing [s@from-sip-external:12] Congestion("PJSIP/anonymous-00000015", "5") in new stack
  == Spawn extension (from-sip-external, s, 12) exited non-zero on 'PJSIP/anonymous-00000015'
    -- Executing [h@from-sip-external:1] Hangup("PJSIP/anonymous-00000015", "") in new stack
  == Spawn extension (from-sip-external, h, 1) exited non-zero on 'PJSIP/anonymous-00000015'
freepbx*CLI>

And sometimes I get that weird behaviour of not being able to correctly pick up the call, as described in the original post. It either keeps ringing or it drops right after the pick up.

Thanks!

Ok. I tried to disable the extension (Line 1) in the SPA, leaving only the trunk (PSTN Line) enabled, but the same erratic behaviour occurs.

Maybe I´ll try to look into the auth_name approach.

That is very unfortunate. Why would someone get help from the community and not return the help received. Sorry to hear that.

Thanks a lot for the input.

I’m very puzzled. Assuming that in Asterisk SIP Settings, pjsip tab, Endpoint Identifier Order is at the default with IP address first, and there is only one endpoint at the SPA’s address, I don’t understand why it doesn’t match. At the Asterisk command prompt, type
pjsip show endpoints
and post the output, which might have a clue.

Trunk > pjsip Settings > Advanced > Match Inbound Authentication is set to “Default”.

Settings > Asterisk SIP settings > SIP Settings [chan_pjsip] > Endpoint Identifier Order is “ip”, “username”, “anonymous”, “header” and “auth_username”

Here it goes:

freepbx*CLI> pjsip show endpoints

 Endpoint:  <Endpoint/CID.....................................>  <State.....>  <Channels.>
    I/OAuth:  <AuthId/UserName...........................................................>
        Aor:  <Aor............................................>  <MaxContact>
      Contact:  <Aor/ContactUri..........................> <Hash....> <Status> <RTT(ms)..>
  Transport:  <TransportId........>  <Type>  <cos>  <tos>  <BindAddress..................>
   Identify:  <Identify/Endpoint.........................................................>
        Match:  <criteria.........................>
    Channel:  <ChannelId......................................>  <State.....>  <Time.....>
        Exten: <DialedExten...........>  CLCID: <ConnectedLineCID.......>
==========================================================================================

 Endpoint:  106/106                                              Not in use    0 of inf
     InAuth:  106-auth/106
        Aor:  106                                                1
      Contact:  106/sip:[email protected]:5060            5a14e859dc Avail         7.122

 Endpoint:  anonymous                                            Unavailable   0 of inf

 Endpoint:  dpma_endpoint                                        Unavailable   0 of inf

 Endpoint:  pstn                                                 Not in use    0 of inf
    OutAuth:  pstn/pstn
        Aor:  pstn                                               1
      Contact:  pstn/sip:[email protected]:5060            5ee615f4ae Avail        14.745
  Transport:  0.0.0.0-udp               udp      3     96  0.0.0.0:5060


Objects found: 4

And here is the SPA’s Line 1 (configured to extension 102 - chan_sip):

freepbx*CLI> sip show peers
Name/username             Host                                    Dyn Forcerport Comedia    ACL Port     Status      Description
102/102                   192.168.10.3                             D  Yes        Yes         A  5160     OK (9 ms)  
1 sip peers [Monitored: 1 online, 0 offline Unmonitored: 0 online, 0 offline]

Thanks.

Disable registration for FXO port and leave registration enabled only for FXS port.

Hello, @arielgrin. As mentioned in the original post, if I set Authentication and Registrarion to “no”, it all works:

The question is how to make it work with authentication and registration turned on.

Thanks.

The issue with registration and authentication is that the SPA sends the caller ID on the “From” field and I don’t think there is a way to change it. With chan_sip it is just a matter of setting insecure=invite to make the caller ID work, but I don’t know if there is a similar parameter for pjsip.

1 Like

Thanks for the clarification, @arielgrin!

What I don´t understand is the outbound authentication should allow unauthenticated calls in from the SPA, but it doesn´t.

[…] ‘Outbound’, which authenticates calls going out, and allows unauthenticated calls in from the other server

Why the FreePBX box is treating the SPA as an unkonwn or anonymous source, if the SPA is successfully authenticating to it?

Thanks again!

Outbound means calls going from SIP to analog FXO, inbound is the other way round.

Sure! That´s why it doesn´t make sense FreePBX blocking incoming calls from the SPA. The authentication method explicitly says unauthenticated inbound calls are allowed.

PJSIP is somehow not able to play nice when two different authentications come from the same IP, as is the case with SPA3102.
You either stay with PJSIP for both FXS and FXO and disable all authentication for the FXO port or move to CHAN_SIP for the FXO port if you really really want to use authentication.

Ok, this workaround from @Stewart1 works perfectly.

Basically, you can create two trunks.

One with “Outbound” for Authentication and “Receive” for Registration. This is the trunk the SPA will register to.

Then, you create another trunk, a dummy one, with “None” for Authentication and “None” for Registration, and in this one you put the SPA IP address in the “SIP Server” field and the port in the “SIP Server Port” field.

Now, inbound calls will still not be matched by username (as it was already happening), but they will be matched by IP, and they will be routed to “from-pstn”, instead of being routed to “from-sip-external”, which was causing the “unknown” or “anonymous” calls issue.

You don´t need the Match (Permit) setting in the advanced tab.

But why does this work with two separate trunks and not with just one? How could we combine the two into only one trunk and make it work with Outbound authentication and Receive registration?

Thanks!

EDIT: No, it does not work entirely. Although it works right away, after a while, the trunk receiving the registration stops and becomes unavailable. The dummy trunk, with no authentication and registration, stays available.

Endpoint:  dummy_pstn                                           Not in use    0 of inf
Aor:  dummy_pstn                                         0
Contact:  dummy_pstn/sip:192.168.10.3:5060           a1d8ff1395 Avail         5.185
Transport:  0.0.0.0-udp               udp      3     96  0.0.0.0:5060
Identify:  dummy_pstn/dummy_pstn
Match: 192.168.10.3/32

Endpoint:  pstn                                                 Unavailable   0 of inf
OutAuth:  pstn/pstn
Aor:  pstn                                               1
Transport:  0.0.0.0-udp               udp      3     96  0.0.0.0:5060

So back to just one trunk with no authentication and registration for now.

It is always best to have separate in and out routes (trunks) even if the carrier is the same, that way you see them as separate entities, (which they indeed are)

Hola Luis Felipe
Yo lo tengo funcionando todo con FreePBX escríbeme a carloszr@gmail para pasarte la documentación.
Saludes

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