SOLVED! - Help with using FreePBX distro as SBC for Lync to AT&T BVOIP

Good day. I am in the final few feet of my quest to remove my Sonus SBC and use Asterisk as the gateway between Lync 2013 and an AT&T BVOIP router. I have calls moving in and out for 90% of users. All calls come in fine and are routed to Lync properly and can be answered, put on hold, and transferred as expected. I have just a few (10 that I know of out of 400) Lync users that cannot dial out through Asterisk. The message I am getting is:

[2016-11-16 04:42:13] NOTICE[11065][C-0000003d]: chan_sip.c:26260 handle_request_invite: Call from ‘’ (10.1.10.76:52237) to extension ‘1585*******’ rejected because extension not found in context ‘default’.

Note that I replaced the dialed number with asterisks, but there was a full complete number there. From just about any other phone I can dial out fine. On this box there are no extensions setup. All I have is a catch all inbound route going to the Lync Trunk, and an outbound route for the typical numbers (911, 10 digit, 11 digit, international). I thought I was onto something because the Lync users did not have a phone number populated in Active Directory (hence the “blank” quotes after Call From.) Populating the number in AD doesn’t do it either. I have tried multiple settings in my SIP trunk options.

If it helps, all of the phones that fail seem to be “non users” - such as a front desk, guest phone, etc. They are setup the same in Lync with an active directory account, enterprise voice, standard URI (tel:+1312xxxxxxx;ext=10xxxx)

It works fine with the same users going through the Sonus SBC, which is doing nothing more than translating UDP SIP to TCP SIP. Below are most of the settings that I have configured - if there is anything else you would like to see, let me know. Thanks for the help. BTW - I went through heck getting this to work - a nice Blog post about my adventure will follow when Im done, in the hopes no one else has to go through this like I did…

TrunkToLync
Outgoing Peer Details - name - connect-with-lync
type=friend
transport=tcp
qualify=yes
promiscredir=yes
port=5058
insecure=very
host=10.1.10.75
dtmfmode=rfc2833
context=from-internal
canreinvite=yes

Incoming settings - user context - from-lync
type=friend
transport=tcp
qualify=no
port=5060
insecure=very
context=from-lync

other settings changed from default (and tried as default also)
Asterisk general SIP settings - allow anonymous Yes
Chan_SIP - enable TCP = Yes and added transport=tcp to sip settings

Inbound Route any/any goes directly to trunk-to-lync
Outbound route 911, 10 digit, 11 digit, go to the two AT&T trunks

Im using the latest FreePBX distro 10.13.66-17 , full updated, and Asterisk 13.

There are lots of other things I have tried before posting here, but ill take any advice, hopefully someone else has an idea - thanks!

At first blush, it doesn’t look like your extension context configuration is set up correctly.
Did you set up these (or any) extensions in the PBX when you were configuring it?

Thanks for replying Dave. I do NOT have any extensions setup on this box. It is merely acting as a gateway between Lync and AT&T. All I want it to do is take any calls coming in on the trunk FROM Lync and send it right back out to the trunk with AT&T.

Im just not sure what to change it to get FreePBX to just pass the calls along. But, none of the 400+ Lync extensions will be setup on this Asterisk box. Its just a gateway.

The thing that I cannot understand is that most calls work fine - its just these few extensions that don’t.

I don’t think it’s setup correctly either but you are saying it’s working so I’ll take your word for it.
Normally the trunk type = peer not friend

Change your trunk settings as follows and try if it works.

outgoing settings
type=peer
& all your other settings

incoming settings
type=user
context=from-trunk-sip-lync
nothing else!

Thanks so much. I will be able to test tomorrow morning and Ill post here either way. Thanks for your help!

Update - Thanks again for all the help. I have determined that no matter what I put in the “incoming” SIP settings I have the call issue. BUT - I have made one step forward. I started doing SIP debug traces on good calls and bad calls. I happened to notice that my phone (which works) is homed on Lync1 (there are 3 front end servers in this Lync pool) which is 10.1.10.75. A failed call is from a user homed on Lync2 (10.1.10.76). I changed the host setting in FreePBX from .75 to .76 and VOILA! Calls from the other phone work fine - and of course, my phone broke… So, then I proceeded to make 3 trunks, differentiating the host= line with the 3 IP addresses. That still doesn’t work, it seems to “remember” the last inbound call and only acknowledge that Lync server IP trunk for outbound calls. By the time I figured this out, my maintenance window had passed and I had to fail back to the Sonus. But, I will try again tomorrow. Does anyone know how this should be handled? The 3 separate trunks didn’t seem to work. I didn’t get a chance to try this - but can I have one trunk with settings like this? My other thought is to put the host= in the “incoming” settings and make 3 trunks?

type=peer
transport=tcp
qualify=yes
promiscredir=yes
port=5058
insecure=very
host=10.1.10.74
host=10.1.10.75
host=10.1.10.76
dtmfmode=rfc2833
context=from-internal
canreinvite=yes

EDIT - this did NOT work, ironically, after you save an apply these settings, FreePBX changed the host line to:
host=10.1.10.74&10.1.10.75&10.1.10.76

but it doesn’t work anyway. See below - setup three trunks!

OK - I think I found a way to work through this without having to hit my 30 minute maintenance window at 4am. I already had Lync setup to dial a fictitious “location” with extensions 19xxxx. I then made a Misc Application that goes right to the AT&T trunk (even though it isn’t plugged in). When testing - I can reproduce the error. Note - that I have 3 separate trunks setup in FreePBX, with 3 different names (but they are all setup on ports 5058 and 5060). Note that only the Lync1 trunk shows up in “SIP show peers” - and my 2 test phones are on Lync 2 and Lync 3, hence they do not work. Are the other 2 trunks not showing up because they are all on the same port? How can I handle this? Thanks again for all the help!

pbx*CLI> sip show peers
Name/username Host Dyn Forcerport Comedia ACL Port Status Description
TrunkToATT1 12.194.xxx.xxx Yes Yes 5060 Unmonitored
TrunkToATT2 12.194.xxx.xxx Yes Yes 5060 Unmonitored
connect-with-lync1 10.1.10.74 Yes Yes 5058 Unmonitored
from-lync1 10.1.10.74 Yes Yes 5060 Unmonitored
5 sip peers [Monitored: 1 online, 0 offline Unmonitored: 4 online, 0 offline]
== Using SIP RTP TOS bits 184
== Using SIP RTP CoS mark 5
[2016-11-17 05:50:23] NOTICE[31544][C-00000052]: chan_sip.c:26260 handle_request_invite: Call from ‘’ (10.1.10.75:57417) to extension ‘195555’ rejected because extension not found in context ‘default’.
== Using SIP RTP TOS bits 184
== Using SIP RTP CoS mark 5
[2016-11-17 05:50:28] NOTICE[31553][C-00000053]: chan_sip.c:26260 handle_request_invite: Call from ‘’ (10.1.10.76:65521) to extension ‘195555’ rejected because extension not found in context ‘default’.

I got it! When I put the other 2 trunks in, I used the “duplicate” option, so FreePBX listed them as “disabled”. I manually enabled them and VOILA! All the phones work and all the trunks show up! Thank you so much for all your help. Even though I kinda worked this out here on the forum replying to myself - the help I got here I think helped me trigger things to look at. Again, Ill be writing a full blog post of this adventure when Im finished, so Ill try to remember to put a link here for anyone looking.

Thanks AGAIN!

Here are my trunks now…

TrunkToATT1 12.194.xxx.xxx Yes Yes 5060 Unmonitored
TrunkToATT2 12.194.xxx.xxx Yes Yes 5060 Unmonitored
connect-with-lync1 10.1.10.74 Yes Yes 5058 Unmonitored
connect-with-lync2 10.1.10.75 Yes Yes 5058 Unmonitored
connect-with-lync3 10.1.10.76 Yes Yes 5058 Unmonitored
from-lync1 10.1.10.74 Yes Yes 5060 Unmonitored
from-lync2 10.1.10.75 Yes Yes 5060 Unmonitored
from-lync3 10.1.10.76 Yes Yes 5060 Unmonitored

Other important notes:
I had to disable pjsip and only use chan_sip, AT&T kept rejecting the calls if pjsip was even in the mix. Since AT&T wants UDP and Lync wants TCP, you do need to specify transport=tcp in the Lync trunks. I also had to leave blank every callerid string in every route and trunk. Even though FreePBX warns you this is a bad idea, it was the only way that the outbound callerID from Lync would show up on outbound calls.

update - I had to make these changes to my Asterisk SIP settings because of this warning:
11-18 08:37:19] NOTICE[2359]: chan_sip.c:29402 check_rtp_timeout: Disconnecting call ‘SIP/connect-with-lync1-000002b0’ for lack of RTP activity in 31 seconds
RTP Timeout = 600 (from 30)
RTP Hold Timeout = 900 (from 300)
RTP Keep Alive = 30 (from 0)

new update - trying to get voicemail to email working - saw this error on the email debug:
Nov 21 07:09:24 pbx postfix/smtp[22876]: fatal: open database /etc/postfix/sasl_passwd.db: No such file or directory
So, I had to Run this command -
sudo postmap sasl_passwd
All my emails immediately went out! Not sure if this was just my install, or an issue with an update, or something I inadvertently messed with over the months this box has been running.

Update - had reports of calls dropping - noticed in the logs that they all drop around 30 minutes. Noticed that session timers was 1800 seconds - found these settings on an old website post from 2011 and made these changes in sip settings

session-timers=originate
session-expires=10800

Doing a sip show settings in the CLI confirms the change

Im going to write a full post about this on my blog soon, so ill make sure to copy it here for future generations!

Although I do not use this configuration thank you for sharing the resolution. I am certain it will help people in the future.