Inbound call routing on a SIP trunk for PJSIP?

I’m having some trouble getting my setup to work correctly.

I use a SPA3102 as a gateway device to the PSTN on the FXO port. I also have an old analog phone connected to the FXS port on the SPA3102. The SPA3102 creates two registrations on the SIP server, one for the FXS port (using a local srouce port of 5060) linking to a standard extension, and a second one for the FXO Port (using a local source port of 5061), which matches the trunk definition.

Then there are a number of sip extensions which are phones distributed around the house.

This setup works on my old FreePBX 11.x distro, so we can assume that the SPA3102 and the sip phones are setup correctly.
Then, I installed a fresh FreePBX13 and decided to switch my setup to PJSIP.

The Trunk is also configured as a PJSIP trunk. Since the SPA3102 will register the trunk with the FreePBX server, it is configured (on the PJSIP settings tab of the trunk) for inbound registration and it is setup to receive registration. Consequently, the Sip server and Sip server port fields are greyed out.

My inbound route is set up to react to any DID.

Now, the problem occurs when I receive calls from the PSTN. In the setup that I described, I can see that the inbound call routing fails, and the log files tell me that the system is not able to identify the extension to route the calls to. The SPA 3102 is configured to copy the CID from the PSTN to the SIP communication.

So far, I have found two solutions for this problem, both are suboptimal.
First, I can instruct the SPA not to copy the CID from the PSTN. The „from:“ field will then have the PSTN trunk username, which will then match the correct “trunk” endpoint.
The downside is that I will no longer see the CID on my sip phones, so I’m not knowing who calls me, and it also prevents all further call processing based on CID.

The second solution is to configure the system to identify the IP address of the SPA3102 as belonging to the SIP trunk. I didn’t find a way to do this via the GUI, so I did this via the pjsip.identify_custom.conf:


This configuration will work, but it also means that my extension for the FXS Port on the SPA3102 can no longer register.


  • Is there a way to match not only the IP address, but also the Port, so that I can distinguish between source port 5060 (FXS) and source port 5061 (FXO)?
  • This setup with the identify matches seems a little awkward, are there no better solutions to this kind of setup, which should be quite common, imho.

just go back to using chan sip unless you are a glutton for punishment

I would, but it seems I can’t get my SPA3102 to register the trunk with the chan_sip driver, for resons which I haven’t figured out yet :).

Since you are using both 5060 and 5061, you have to get into the guts of your configuration to set up the incoming so that it listens on more than one port. It’s doable - we’ve been doing it for years to support our “roaming, random-IP” phones.

If you are using PJ-SIP and SIP, you HAVE to use two different ports. It took me several tries on the one machine that I AM using PJ-SIP on to get it all set up correctly. For now (until PJ-SIP is something more than a “Beta with a plan”), I’d recommend setting your incoming to use CHAN-SIP and configure each “trunk” with its own port.

Thanks for the insight.

I took a hint, and went back to chan_sip for the trunk. The endpoints seem to be doing fine on PJSIP for the moment.



I am having to do the same. It does seem silly there is not a better way to handle this other than using two different SIP drivers within FreePBX.

i would be nice to know I am using pjSIP for trunks as well as extensions.

With the move to remove Chan-SIP and replace it with PJ-SIP, there isn’t a really good way to do it without losing important functionality. As PJ-SIP gets closer to matching the functionality of Chan-SIP, it will be easier and easier to make this happen.

Given the choice between running two channel drivers that have different functionality and losing the ability to connect to “legacy” SIP providers, I’d take two channel drivers. By the way, we already have eight or nine channel drivers (DAHDI, Skinny, SCCP, H323, etc.), so a couple that do different kinds of SIP isn’t actually particularly silly.

so, does this mean @tkuehne, you are using both chan_sip and pj_sip on FreePBX ?

I just set up my SPA3102 with a PJSIP trunk and have both caller ID being passed fine and the call being sent onto a ring group without any issues. This is the set up I used if it helps.

I can dial in and out fine with Called ID working on all my phones.

had the same thing and here is how i solved it:

admin --> config edit module

–> pjsip.aor_custom_post.conf

–> add these two lines :

 contact=sip:[email protected]:5060

Before adding custom context, did you try the various advanced settings in the trunk setup?

1 Like

yes i tried
this little addition wont affect anything.
try it. it is perfect.

I didn’t have Line1 on my SPA3102 registered when I did my set up, but just out of interest I did try and register it to a PJSIP extension and both the Line1 & PSTN Line seemed to register fine, Line 1 on 5060 and PSTN on 5062?

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