Lync gateway

Dear All,
What i am trying to achieve for the moment is to make freePBX a gateway to our sip provider for our Microsoft lync server. All the sip clients for the moment are connected to microsoft lync server. The reason i do this, is because our sip provider accept only sip over UDP while microsoft lync doesn’t. I have read this post here http://www.sipstories.com/2012/06/25/how-to-integrate-microsoft-lync-2010-asterisk-and-a-sip-trunk/
how to do it,but without success. On the lync side everything is configured and working. The first problem which i face is that even i have configured a trunk from GUI for our link server the settings like this:
host=x.x.x.x
transport=tcp
port=5068
insecure=very
type=friend
context=from-internal
promiscredir=yes
qualify=yes
canreinvite=yes
But when i try to telnet on port 5068 on freepbx server it fails, while i can succefylly telnet on port 50558 on our lync server. I have checked that firewall and selinux is disabled.I have also run the follwing command to be sure port 5068 is opend
:iptables -A INPUT -p tcp -m tcp --dport 5068 -j ACCEPT. On port 5060 i cal succesfully telnet. The second and most dificult i suppose problem is, when a call comes from my sip provider, i can see the call comming like this:

<<<<<<<== Using SIP RTP TOS bits 184
== Using SIP RTP CoS mark 5
– Executing [xxxxxxxxx@from-trunk:1] Set(“SIP/Cable-00000002”, “__FROM_DID=xxxxxxxxx”) in new stack
– Executing [xxxxxxxxx@from-trunk:2] Goto(“SIP/Cable-00000002”, “s,1”) in new stack
– Goto (from-trunk,s,1)
– Executing [s@from-trunk:1] ExecIf(“SIP/Cable-00000002”, “0?Set(__FROM_DID=s)”) in new stack
– Executing [s@from-trunk:2] ExecIf(“SIP/Cable-00000002”, “1 ?Set(CALLERID(name)=yyyyyyyyy)”) in new stack
– Executing [s@from-trunk:3] Set(“SIP/Cable-00000002”, “__CALLINGPRES_SV=allowed_not_screened”) in new stack
– Executing [s@from-trunk:4] Set(“SIP/Cable-00000002”, “CALLERPRES()=allowed_not_screened”) in new stack
– Executing [s@from-trunk:5] Goto(“SIP/Cable-00000002”, “from-did-direct,xxxxxxxxx,1”) in new stack
– Goto (from-did-direct,xxxxxxxxx,1)
– Executing [xxxxxxxxx@from-did-direct:1] Macro(“SIP/Cable-00000002”, “exten-vm,novm,xxxxxxxxx”) in new stack
– Executing [s@macro-exten-vm:1] Macro(“SIP/Cable-00000002”, “user-callerid,”) in new stack
– Executing [s@macro-user-callerid:1] Set(“SIP/Cable-00000002”, “AMPUSER=yyyyyyyyy”) in new stack
– Executing [s@macro-user-callerid:2] GotoIf(“SIP/Cable-00000002”, “0?report”) in new stack
– Executing [s@macro-user-callerid:3] ExecIf(“SIP/Cable-00000002”, “1?Set(REALCALLERIDNUM=yyyyyyyyy)”) in new stack
– Executing [s@macro-user-callerid:4] Set(“SIP/Cable-00000002”, “AMPUSER=”) in new stack
– Executing [s@macro-user-callerid:5] Set(“SIP/Cable-00000002”, “AMPUSERCIDNAME=”) in new stack
– Executing [s@macro-user-callerid:6] GotoIf(“SIP/Cable-00000002”, “1?report”) in new stack
– Goto (macro-user-callerid,s,9)
– Executing [s@macro-user-callerid:9] GotoIf(“SIP/Cable-00000002”, “0?continue”) in new stack
– Executing [s@macro-user-callerid:10] Set(“SIP/Cable-00000002”, “__TTL=64”) in new stack
– Executing [s@macro-user-callerid:11] GotoIf(“SIP/Cable-00000002”, “1?continue”) in new stack
– Goto (macro-user-callerid,s,18)
– Executing [s@macro-user-callerid:18] NoOp(“SIP/Cable-00000002”, “Using CallerID “yyyyyyyyy” “) in new stack
– Executing [s@macro-exten-vm:2] Set(“SIP/Cable-00000002”, “RingGroupMethod=none”) in new stack
– Executing [s@macro-exten-vm:3] Set(“SIP/Cable-00000002”, “VMBOX=novm”) in new stack
– Executing [s@macro-exten-vm:4] Set(“SIP/Cable-00000002”, “EXTTOCALL=xxxxxxxxx”) in new stack
– Executing [s@macro-exten-vm:5] Set(“SIP/Cable-00000002”, “CFUEXT=”) in new stack
– Executing [s@macro-exten-vm:6] Set(“SIP/Cable-00000002”, “CFBEXT=”) in new stack
– Executing [s@macro-exten-vm:7] Set(“SIP/Cable-00000002”, “RT=”””) in new stack
– Executing [s@macro-exten-vm:8] Macro(“SIP/Cable-00000002”, “record-enable,xxxxxxxxx,IN”) in new stack
– Executing [s@macro-record-enable:1] GotoIf(“SIP/Cable-00000002”, “1?check”) in new stack
– Goto (macro-record-enable,s,4)
– Executing [s@macro-record-enable:4] ExecIf(“SIP/Cable-00000002”, “0?MacroExit()”) in new stack
– Executing [s@macro-record-enable:5] GotoIf(“SIP/Cable-00000002”, “0?Group:OUT”) in new stack
– Goto (macro-record-enable,s,16)
– Executing [s@macro-record-enable:16] GotoIf(“SIP/Cable-00000002”, “1?IN”) in new stack
– Goto (macro-record-enable,s,21)
– Executing [s@macro-record-enable:21] ExecIf(“SIP/Cable-00000002”, “1?MacroExit()”) in new stack
– Executing [s@macro-exten-vm:9] Macro(“SIP/Cable-00000002”, “dial,tr,xxxxxxxxx”) in new stack
– Executing [s@macro-dial:1] GotoIf(“SIP/Cable-00000002”, “1?dial”) in new stack
– Goto (macro-dial,s,3)
– Executing [s@macro-dial:3] AGI(“SIP/Cable-00000002”, “dialparties.agi”) in new stack
– Launched AGI Script /var/lib/asterisk/agi-bin/dialparties.agi
dialparties.agi: Starting New Dialparties.agi
dialparties.agi: Caller ID name is ‘yyyyyyyyy’ number is 'yyyyyyyyy’
dialparties.agi: Methodology of ring is ‘none’
– dialparties.agi: Added extension xxxxxxxxx to extension map
– dialparties.agi: Extension xxxxxxxxx cf is disabled
– dialparties.agi: Extension xxxxxxxxx do not disturb is disabled
dialparties.agi: EXTENSION_STATE: 4 (UNAVAILABLE)
– dialparties.agi: dbset CALLTRACE/xxxxxxxxx to yyyyyyyyy
– dialparties.agi: Filtered ARG3: xxxxxxxxx
– <SIP/Cable-00000002>AGI Script dialparties.agi completed, returning 0
– Executing [s@macro-dial:7] Dial(“SIP/Cable-00000002”, “SIP/xxxxxxxxx,tr”) in new stack
== Using SIP RTP TOS bits 184
== Using SIP RTP CoS mark 5
== Everyone is busy/congested at this time (1:0/0/1)
– Executing [s@macro-dial:8] Set(“SIP/Cable-00000002”, “DIALSTATUS=CHANUNAVAIL”) in new stack
– Executing [s@macro-dial:9] GosubIf(“SIP/Cable-00000002”, “0?CHANUNAVAIL,1”) in new stack
– Executing [s@macro-exten-vm:10] GotoIf(“SIP/Cable-00000002”, “0?exit,return”) in new stack
– Executing [s@macro-exten-vm:11] Set(“SIP/Cable-00000002”, “SV_DIALSTATUS=CHANUNAVAIL”) in new stack
– Executing [s@macro-exten-vm:12] GosubIf(“SIP/Cable-00000002”, “0?docfu,1”) in new stack
– Executing [s@macro-exten-vm:13] GosubIf(“SIP/Cable-00000002”, “0?docfb,1”) in new stack
– Executing [s@macro-exten-vm:14] Set(“SIP/Cable-00000002”, “DIALSTATUS=CHANUNAVAIL”) in new stack
– Executing [s@macro-exten-vm:15] NoOp(“SIP/Cable-00000002”, “Voicemail is ‘novm’”) in new stack
– Executing [s@macro-exten-vm:16] GotoIf(“SIP/Cable-00000002”, “1?s-CHANUNAVAIL,1”) in new stack
– Goto (macro-exten-vm,s-CHANUNAVAIL,1)
– Executing [s-CHANUNAVAIL@macro-exten-vm:1] NoOp(“SIP/Cable-00000002”, "IVR_RETVM: IVR_CONTEXT: ") in new stack
– Executing [s-CHANUNAVAIL@macro-exten-vm:2] GotoIf(“SIP/Cable-00000002”, “0?exit,1”) in new stack
– Executing [s-CHANUNAVAIL@macro-exten-vm:3] PlayTones(“SIP/Cable-00000002”, “congestion”) in new stack
– Executing [s-CHANUNAVAIL@macro-exten-vm:4] Congestion(“SIP/Cable-00000002”, “10”) in new stack
== Spawn extension (macro-exten-vm, s-CHANUNAVAIL, 4) exited non-zero on ‘SIP/Cable-00000002’ in macro ‘exten-vm’
== Spawn extension (from-did-direct, xxxxxxxxx, 1) exited non-zero on ‘SIP/Cable-00000002’>>>>>>>

Any help for any problem is welcomed.thx
Regards
Pantos

I have finally figured out by playing around and create inbound route to and map to extension 1000. then i edit this extension and add SIP/lync/224 to dial section and magic, i could dial from outside world to my lync phone. I know this is done by lack i didnot even know what i was doing, i suppose there should be easier way. I really appreciate any help on both my problems

Finlay it was very simple, and everything worked, below is my configuration in case someone else need to do the same thing. follow this three steps
1.add in sip.conf these lines
tcpenabled=yes
tcpbindaddr=0.0.0.0:5068
2.Configure trunks for your provider and lync the way you can find many post on the internet. the importan part here is to add the follwoing line on both trunks
context=from-internal
3. Last step is to create the 2 ouband rules for lync and for provider. thats all