I have a setup of Asterisk PBX running on a Raspberry Pi 1 (IP 192.168.2.2) and it runs a few local IP phones just fine. I recently purchased a Grandstream HT813 gateway (IP 192.168.2.3) to connect both an analog phone to IP and IP to the PSTN.
The analog phone works perfectly and dialing in from the PSTN works perfectly. Dialing out was much more problematic. First of all, I have the following in my sip.conf: (I didn't include the other phones, just the FXO port)
[general]
context=default
sipdebug=yes
bindaddr=0.0.0.0
[FXO]
type=peer
context=inbound
host=192.168.2.3
insecure=port
dtmfmode=rfc2833
canreinvite=no
secret=secret_was_here
I redacted the secret above for obvious reasons. When I dail out to the PSTN via a IP phone (IP 192.168.2.5), I get the following error, where [myphonenumber] is my cell phone number that I was calling to test:
== Setting global variable 'SIPDOMAIN' to '192.168.2.2'
-- Executing [[myphonenumber]@local:1] Goto("PJSIP/104-00000000", "dialout,[myphonenumber],1") in new stack
-- Goto (dialout,[myphonenumber],1)
-- Executing [[myphonenumber]@dialout:1] Dial("PJSIP/104-00000000", "SIP/FXO/[myphonenumber], 30") in new stack
== Using SIP RTP CoS mark 5
Audio is at 13370
Adding codec ulaw to SDP
Adding codec alaw to SDP
Adding codec gsm to SDP
Adding non-codec 0x1 (telephone-event) to SDP
Reliably Transmitting (no NAT) to 192.168.2.3:5060:
INVITE sip:[myphonenumber]@192.168.2.3 SIP/2.0
Via: SIP/2.0/UDP 192.168.2.2:5060;branch=z9hG4bK71b94203
Max-Forwards: 70
From: <sip:104@192.168.2.2>;tag=as162b0b68
To: <sip:[myphonenumber]@192.168.2.3>
Contact: <sip:104@192.168.2.2:5060>
Call-ID: 3dc727711219fa6e4171966d519ac8ee@192.168.2.2:5060
CSeq: 102 INVITE
User-Agent: Asterisk PBX 16.2.1~dfsg-1
Date: Thu, 15 Aug 2019 19:11:17 GMT
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces, timer
Content-Type: application/sdp
Content-Length: 291
v=0
o=root 1202030057 1202030057 IN IP4 192.168.2.2
s=Asterisk PBX 16.2.1~dfsg-1
c=IN IP4 192.168.2.2
t=0 0
m=audio 13370 RTP/AVP 0 8 3 101
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000
a=rtpmap:3 GSM/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
a=maxptime:150
a=sendrecv
---
[Aug 15 20:11:17] ERROR[23679][C-00000001]: chan_sip.c:4321 __sip_reliable_xmit: Serious Network Trouble; __sip_xmit returns error for pkt data
So I set up a switch port to mirror the output of my Asterisk server Pi. It sends no data to the gateway when this error occurs, so the problem is in Asterisk. I have seen many posts saying that this is a permission or firewall error, of course. First of all, I disabled the firewall on the Asterisk server during testing. (It's a small network) I also ran nmap -v -sU -p 5060 192.168.2.3, which confirmed that my gateway is working just fine. If I run that command as the Asterisk user, I get a permission error, of course. I see nothing else in the syslog. Any ideas?
UPDATE: I had another look at it and I traced the call through the C code. It looks like the issue is that the sipsock variable (line 1101) is set to -1 when sip_prepare_socket confirms that the connection requires a UDP socket (line 29503). This returns -1 throwing an error into __sip_xmit. I will search my log files for any additional information. Also, my Asterisk version is v16.2.1.