Hello all,

I recently built an SBC to integrate Kamailio with MS Teams following Henning Westerholt blob post and all the other awesome tips I was able to find here in the list.

Everything is working great. The only missing piece I would like some thoughts on is about why MS Teams is not accepting the BYE sent from Kamailio. 
It eventually replies with "504 Server Time-out"

The below trace shows the entire call.

||||||||||||||||||||
====================
tag: rcv
pid: 3381
process: 63
time: 1627070235.086307
date: Fri Jul 23 19:57:15 2021
proto: tls ipv4
srcip: 52.114.76.76
srcport: 4672
dstip: SBC_IP_ADDR
dstport: 5061
~~~~~~~~~~~~~~~~~~~~
INVITE sip:+5515XXXXXXXXX@SBC-FQDN:5061;user=phone;transport=tls SIP/2.0
FROM: "Last, First Name"<sip:+8979994;ext=01180@sip.pstnhub.microsoft.com:5061;user=phone>;tag=bafa0f5a573749a7b494917c0309f544
TO: <sip:+5515XXXXXXXXX@SBC-FQDN:5061;user=phone>
CSEQ: 1 INVITE
CALL-ID: c9b2aa4f658f5788aa7090bef0f5e35e
MAX-FORWARDS: 70
VIA: SIP/2.0/TLS 52.114.76.76:5061;branch=z9hG4bK60895c91
RECORD-ROUTE: <sip:sip-du-a-eu.pstnhub.microsoft.com:5061;transport=tls;lr>
CONTACT: <sip:api-du-b-usea2.pstnhub.microsoft.com:443;x-i=a82f1d71-4e21-42a8-8389-2ae26e54610f;x-c=c9b2aa4f658f5788aa7090bef0f5e35e/d/8/b14037a741dd46a79c74dce15912782c>
CONTENT-LENGTH: 1103
MIN-SE: 300
SUPPORTED: timer
USER-AGENT: Microsoft.PSTNHub.SIPProxy v.2021.6.15.17 i.EUNO.0
CONTENT-TYPE: application/sdp
ALLOW: INVITE,ACK,OPTIONS,CANCEL,BYE,NOTIFY
PRIVACY: id
SESSION-EXPIRES: 3600

v=0
o=- 599625 0 IN IP4 127.0.0.1
s=session
c=IN IP4 52.113.58.181
b=CT:10000000
t=0 0
m=audio 50122 RTP/SAVP 104 9 103 111 18 0 8 97 101 13 118
c=IN IP4 52.113.58.181
a=rtcp:50123
a=ice-ufrag:fTy/
a=ice-pwd:tQKGN0Szi7Q/vTdf6SiXUSpj
a=rtcp-mux
a=candidate:1 1 UDP 2130706431 52.113.58.181 50122 typ srflx raddr 10.0.33.230 rport 50122
a=candidate:1 2 UDP 2130705918 52.113.58.181 50123 typ srflx raddr 10.0.33.230 rport 50123
a=candidate:2 1 tcp-act 2121006078 52.113.58.181 49152 typ srflx raddr 10.0.33.230 rport 49152
a=candidate:2 2 tcp-act 2121006078 52.113.58.181 49152 typ srflx raddr 10.0.33.230 rport 49152
a=label:main-audio
a=mid:1
a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:PC00Mgk39GjTYJ+mUSNQg++TU6zJKar4VYDj4/ET|2^31
a=sendrecv
a=rtpmap:104 SILK/16000
a=rtpmap:9 G722/8000
a=rtpmap:103 SILK/8000
a=rtpmap:111 SIREN/16000
a=fmtp:111 bitrate=16000
a=rtpmap:18 G729/8000
a=fmtp:18 annexb=no
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000
a=rtpmap:97 RED/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
a=rtpmap:13 CN/8000
a=rtpmap:118 CN/16000
a=ptime:20
||||||||||||||||||||
====================
tag: snd
pid: 3381
process: 63
time: 1627070235.089106
date: Fri Jul 23 19:57:15 2021
proto: tls ipv4
srcip: SBC_IP_ADDR
srcport: 5061
dstip: 52.114.76.76
dstport: 4672
~~~~~~~~~~~~~~~~~~~~
SIP/2.0 100 trying -- your call is important to us
FROM: "Last, First Name"<sip:+8979994;ext=01180@sip.pstnhub.microsoft.com:5061;user=phone>;tag=bafa0f5a573749a7b494917c0309f544
TO: <sip:+5515XXXXXXXXX@SBC-FQDN:5061;user=phone>
CSEQ: 1 INVITE
CALL-ID: c9b2aa4f658f5788aa7090bef0f5e35e
VIA: SIP/2.0/TLS 52.114.76.76:5061;branch=z9hG4bK60895c91;rport=4672
Server: kamailio (5.3.7 (x86_64/linux))
Content-Length: 0

||||||||||||||||||||
====================
tag: snd
pid: 3291
process: 18
time: 1627070235.111825
date: Fri Jul 23 19:57:15 2021
proto: tls ipv4
srcip: SBC_IP_ADDR
srcport: 5061
dstip: 52.114.76.76
dstport: 4672
~~~~~~~~~~~~~~~~~~~~
SIP/2.0 180 Ringing
FROM: "Last, First Name"<sip:+8979994;ext=01180@sip.pstnhub.microsoft.com:5061;user=phone>;tag=bafa0f5a573749a7b494917c0309f544
t:<sip:+5515XXXXXXXXX@SBC-FQDN:5061;user=phone>;tag=e55N8paBUgZac
CALL-ID: c9b2aa4f658f5788aa7090bef0f5e35e
CSEQ: 1 INVITE
m:<sip:+5515XXXXXXXXX@192.168.1.254:5060;transport=udp>
User-Agent:FreeSWITCH-mod_sofia/1.10.3-release~64bit
Accept:application/sdp
Allow:INVITE,ACK,BYE,CANCEL,OPTIONS,MESSAGE,INFO,UPDATE,REGISTER,REFER,NOTIFY
k:path,replaces
u:talk,hold,conference,refer
l:0
Via: SIP/2.0/TLS 52.114.76.76:5061;rport=4672;branch=z9hG4bK60895c91
Record-Route: <sip:192.168.1.253:5060;r2=on;ftag=bafa0f5a573749a7b494917c0309f544;lr=on>,<sip:SBC-FQDN:5061;transport=tls;r2=on;ftag=bafa0f5a573749a7b494917c0309f544;lr=on>
Record-Route: <sip:sip-du-a-eu.pstnhub.microsoft.com:5061;transport=tls;lr>
P-SR-XBranch: z9hG4bKe7d4.5ae277881edb9c04a7ac65af016e582e.0

||||||||||||||||||||
====================
tag: snd
pid: 3298
process: 21
time: 1627070245.043621
date: Fri Jul 23 19:57:25 2021
proto: tls ipv4
srcip: SBC_IP_ADDR
srcport: 5061
dstip: 52.114.76.76
dstport: 4672
~~~~~~~~~~~~~~~~~~~~
SIP/2.0 183 Session Progress
FROM: "Last, First Name"<sip:+8979994;ext=01180@sip.pstnhub.microsoft.com:5061;user=phone>;tag=bafa0f5a573749a7b494917c0309f544
t:<sip:+5515XXXXXXXXX@SBC-FQDN:5061;user=phone>;tag=e55N8paBUgZac
CALL-ID: c9b2aa4f658f5788aa7090bef0f5e35e
CSEQ: 1 INVITE
m:<sip:+5515XXXXXXXXX@192.168.1.254:5060;transport=udp>
User-Agent:FreeSWITCH-mod_sofia/1.10.3-release~64bit
Allow:INVITE,ACK,BYE,CANCEL,OPTIONS,MESSAGE,INFO,UPDATE,REGISTER,REFER,NOTIFY
k:path,replaces
u:talk,hold,conference,refer
c:application/sdp
Content-Disposition:session
l:323
Via: SIP/2.0/TLS 52.114.76.76:5061;rport=4672;branch=z9hG4bK60895c91
Record-Route: <sip:192.168.1.253:5060;r2=on;ftag=bafa0f5a573749a7b494917c0309f544;lr=on>,<sip:SBC-FQDN:5061;transport=tls;r2=on;ftag=bafa0f5a573749a7b494917c0309f544;lr=on>
Record-Route: <sip:sip-du-a-eu.pstnhub.microsoft.com:5061;transport=tls;lr>
P-SR-XBranch: z9hG4bKe7d4.5ae277881edb9c04a7ac65af016e582e.0

v=0
o=FreeSWITCH 1627045233 1627045234 IN IP4 SBC_IP_ADDR
s=FreeSWITCH
c=IN IP4 SBC_IP_ADDR
t=0 0
m=audio 49692 RTP/SAVP 0 101
a=rtpmap:0 PCMU/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
a=ptime:20
a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:eMGqj0jubamtvLsI/E/YSj8UqNKgUB5DTHGWc7PY
a=nortpproxy:yes

||||||||||||||||||||
====================
tag: snd
pid: 3293
process: 19
time: 1627070255.938770
date: Fri Jul 23 19:57:35 2021
proto: tls ipv4
srcip: SBC_IP_ADDR
srcport: 5061
dstip: 52.114.76.76
dstport: 4672
~~~~~~~~~~~~~~~~~~~~
SIP/2.0 200 OK
FROM: "Last, First Name"<sip:+8979994;ext=01180@sip.pstnhub.microsoft.com:5061;user=phone>;tag=bafa0f5a573749a7b494917c0309f544
t:<sip:+5515XXXXXXXXX@SBC-FQDN:5061;user=phone>;tag=e55N8paBUgZac
CALL-ID: c9b2aa4f658f5788aa7090bef0f5e35e
CSEQ: 1 INVITE
m:<sip:+5515XXXXXXXXX@192.168.1.254:5060;transport=udp>
User-Agent:FreeSWITCH-mod_sofia/1.10.3-release~64bit
Allow:INVITE,ACK,BYE,CANCEL,OPTIONS,MESSAGE,INFO,UPDATE,REGISTER,REFER,NOTIFY
k:path,replaces
u:talk,hold,conference,refer
c:application/sdp
Content-Disposition:session
l:323
Via: SIP/2.0/TLS 52.114.76.76:5061;rport=4672;branch=z9hG4bK60895c91
Record-Route: <sip:192.168.1.253:5060;r2=on;ftag=bafa0f5a573749a7b494917c0309f544;lr=on>,<sip:SBC-FQDN:5061;transport=tls;r2=on;ftag=bafa0f5a573749a7b494917c0309f544;lr=on>
Record-Route: <sip:sip-du-a-eu.pstnhub.microsoft.com:5061;transport=tls;lr>
P-SR-XBranch: z9hG4bKe7d4.5ae277881edb9c04a7ac65af016e582e.0

v=0
o=FreeSWITCH 1627045233 1627045234 IN IP4 SBC_IP_ADDR
s=FreeSWITCH
c=IN IP4 SBC_IP_ADDR
t=0 0
m=audio 49692 RTP/SAVP 0 101
a=rtpmap:0 PCMU/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
a=ptime:20
a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:eMGqj0jubamtvLsI/E/YSj8UqNKgUB5DTHGWc7PY
a=nortpproxy:yes

||||||||||||||||||||
====================
tag: rcv
pid: 3370
process: 57
time: 1627070255.957735
date: Fri Jul 23 19:57:35 2021
proto: tls ipv4
srcip: 52.114.76.76
srcport: 4672
dstip: SBC_IP_ADDR
dstport: 5061
~~~~~~~~~~~~~~~~~~~~
ACK sip:+5515XXXXXXXXX@192.168.1.254:5060;transport=udp SIP/2.0
FROM: "Last, First Name"<sip:+8979994;ext=01180@sip.pstnhub.microsoft.com:5061;user=phone>;tag=bafa0f5a573749a7b494917c0309f544
TO: <sip:+5515XXXXXXXXX@SBC-FQDN:5061>;user=phone;tag=e55N8paBUgZac
CSEQ: 1 ACK
CALL-ID: c9b2aa4f658f5788aa7090bef0f5e35e
MAX-FORWARDS: 70
VIA: SIP/2.0/TLS 52.114.76.76:5061;branch=z9hG4bKe3747d68
CONTACT: <sip:api-du-b-usea2.pstnhub.microsoft.com:443;x-i=a82f1d71-4e21-42a8-8389-2ae26e54610f;x-c=c9b2aa4f658f5788aa7090bef0f5e35e/d/8/b14037a741dd46a79c74dce15912782c>
CONTENT-LENGTH: 0
USER-AGENT: Microsoft.PSTNHub.SIPProxy v.2021.6.15.17 i.EUNO.0
ALLOW: INVITE,ACK,OPTIONS,CANCEL,BYE,NOTIFY
Route: <sip:SBC-FQDN:5061;transport=tls;r2=on;ftag=bafa0f5a573749a7b494917c0309f544;lr=on>
Route: <sip:192.168.1.253:5060;r2=on;ftag=bafa0f5a573749a7b494917c0309f544;lr=on>
P-SR-XUID: atpsh-60fb1b5d-d35-1

||||||||||||||||||||
====================
tag: snd
pid: 3302
process: 23
time: 1627070275.228363
date: Fri Jul 23 19:57:55 2021
proto: tls ipv4
srcip: SBC_IP_ADDR
srcport: 5061
dstip: 52.114.75.24
dstport: 5061
~~~~~~~~~~~~~~~~~~~~
BYE sip:52.114.76.76:4672;x-i=a82f1d71-4e21-42a8-8389-2ae26e54610f;x-c=c9b2aa4f658f5788aa7090bef0f5e35e/d/8/b14037a741dd46a79c74dce15912782c SIP/2.0
Record-Route: <sip:SBC-FQDN:5061;transport=tls;r2=on;ftag=e55N8paBUgZac;lr=on>
Record-Route: <sip:192.168.1.253:5060;r2=on;ftag=e55N8paBUgZac;lr=on>
Via: SIP/2.0/TLS SBC_IP_ADDR:5061;branch=z9hG4bK92fc.fcb147cf8e5e6e6e960d0f2401ad6383.0
v:SIP/2.0/UDP 192.168.1.254;received=192.168.1.254;rport=5060;branch=z9hG4bKgvXrQrcNjNj3m
f:<sip:+5515XXXXXXXXX@SBC-FQDN:5061;user=phone>;tag=e55N8paBUgZac
t:"Last, First Name"<sip:+8979994;ext=01180@sip.pstnhub.microsoft.com:5061;user=phone>;tag=bafa0f5a573749a7b494917c0309f544
i:c9b2aa4f658f5788aa7090bef0f5e35e
CSeq:38981345 BYE
User-Agent:FreeSWITCH-mod_sofia/1.10.3-release~64bit
Allow:INVITE,ACK,BYE,CANCEL,OPTIONS,MESSAGE,INFO,UPDATE,REGISTER,REFER,NOTIFY
k:path,replaces
Reason:Q.850;cause=16;text="NORMAL_CLEARING"
Max-Forwards: 64
l:0
Route: <sip:sip-du-a-eu.pstnhub.microsoft.com:5061;transport=tls;lr>
P-SR-XUID: atpsh-60fb1b5d-d35-1

||||||||||||||||||||
====================
tag: rcv
pid: 3385
process: 65
time: 1627070300.423499
date: Fri Jul 23 19:58:20 2021
proto: tls ipv4
srcip: 52.114.75.24
srcport: 5061
dstip: SBC_IP_ADDR
dstport: 5061
~~~~~~~~~~~~~~~~~~~~
SIP/2.0 504 Server Time-out
FROM: <sip:+5515XXXXXXXXX@SBC-FQDN:5061;user=phone>;tag=e55N8paBUgZac
TO: "Last, First Name"<sip:+8979994;ext=01180@sip.pstnhub.microsoft.com:5061;user=phone>;tag=bafa0f5a573749a7b494917c0309f544
CSEQ: 38981345 BYE
CALL-ID: c9b2aa4f658f5788aa7090bef0f5e35e
VIA: SIP/2.0/TLS SBC_IP_ADDR:5061;branch=z9hG4bK92fc.fcb147cf8e5e6e6e960d0f2401ad6383.0
CONTENT-LENGTH: 0
ALLOW: INVITE,ACK,OPTIONS,CANCEL,BYE,NOTIFY
SERVER: Microsoft.PSTNHub.SIPProxy v.2021.6.15.17 i.EUWE.3
Via: SIP/2.0/UDP 192.168.1.254;received=192.168.1.254;rport=5060;branch=z9hG4bKgvXrQrcNjNj3m
Record-Route: <sip:SBC-FQDN:5061;transport=tls;r2=on;ftag=e55N8paBUgZac;lr=on>,<sip:192.168.1.253:5060;r2=on;ftag=e55N8paBUgZac;lr=on>
P-SR-XBranch: z9hG4bK92fc.fcb147cf8e5e6e6e960d0f2401ad6383.0