Incoming DID from PSTN not working

Hi everyone!

My first post, please bear with me…
I’m a bit clueless to where to go from here.

Here is what I’m trying to do:
Getting PSTN calls through to the Asterisk server (via my DID numbers from didlogic). E.g I’m trying to call my Finnish Number 358-323233232-2 which I got from DIDlogic, and I’ve setup the number in a2billing with DID destination to the SIP/asterisk-client-nr.

I’ve opened all ports in my router (from 1-65000 TCP and UDP) to my server, so I’m not sure where to look anymore. IPTables is cleared on the Asterisk Server for now. Been trying to figure this out now for the last week, with tweaking the config files up and down, not sure what is right or wrong anymore.

Here is what I’m running:
Operation System Version : Ubuntu 12.04.2 LTS
Asterisk Version : 1.8
PHP Version : 5.3.10-1ubuntu3.5
A2Billing Version : 2.0.1

The Asterisk server has IP: 192.168.1.101
ISP public IP: Dynamic.
Router: Zyxel CheapCheap-Router/Switch

Here are my config files:

sip.conf:
[general]
register => XXXXX:XXXX@sip.didlogic.net
bindport=5060
bindaddr=0.0.0.0
context=a2billing
;allowoverlap=no
rtcachefriend=yes
disallow=all
allow=ulaw
allow=gsm
allow=g711
dtmfmode=rf2833
progressinband=never
srvlookup=no
insecure=port,invite
nat=yes
externip=voip.mydomain.com
localnet=192.168.0.0/255.255.0.0
host=dynamic
qualify=yes
canreinvite=no

[siptrunk]
host=sip.didlogic.net
type=peer
insecure=port,invite
nat=yes
username=XXXXXX
secret=XXXXX
sendrpid=yes
canreinvite=no
context=a2billing
allow=ulaw,gsm,g711
host=dynamic
qualify=yes


extensions.conf:
[general]
static=yes
writeprotect=no
clearglobalvars=no

[a2billing]
switch => Realtime


extconfig.conf:
[settings]
sipusers => mysql,asterisk_database_name,cc_sip_buddies
sippeers => mysql,asterisk_database_name,cc_sip_buddies
voicemail => mysql,asterisk_database_name,voicemail
extensions => mysql,asterisk_database_name,extensions


‘extensions’ from ‘asterisk_database_name’:

±---------±-------------±-----±----±--------±---------------+
| Field | Type | Null | Key | Default | Extra |
±---------±-------------±-----±----±--------±---------------+
| id | int(11) | NO | MUL | NULL | auto_increment |
| context | varchar(20) | NO | PRI | | |
| exten | varchar(20) | NO | PRI | | |
| priority | tinyint(4) | NO | PRI | 0 | |
| app | varchar(20) | NO | | | |
| appdata | varchar(128) | NO | | | |
±---------±-------------±-----±----±--------±---------------+

mysql> select * from extensions;
±—±----------±------±---------±-------±----------------+
| id | context | exten | priority | app | appdata |
±—±----------±------±---------±-------±----------------+
| 1 | a2billing | _X. | 1 | NoOp | A2Billing Start |
| 2 | a2billing | _X. | 2 | AGI | a2billing.php,1 |
| 3 | a2billing | _X. | 3 | Hangup | |
±—±----------±------±---------±-------±----------------+


res_config_mysql.conf:
[asterisk_xxxxx]
dbhost = 127.0.0.1
dbname = asterisk_database_name
dbuser = asterisk_database_user_name
dbpass = asterisk_database_password
dbport = 3306
dbsock = /tmp/mysql.sock


modules.conf:
[modules]
autoload=yes
load => res_config_mysql.so
load => app_realtime.so
load => func_realtime.so
load => pbx_realtime.so


Here is the error I get:

== Using SIP RTP CoS mark 5
– Executing [DID_NUMBER_I_CALLED@a2billing:1] NoOp(“SIP/9413927163-0000001f”, “A2Billing Start”)
– Executing [DID_NUMBER_I_CALLED@a2billing:2] AGI(“SIP/9413927163-0000001f”, “a2billing.php,1”)
– Launched AGI Script /usr/share/asterisk/agi-bin/a2billing.php
– AGI Script Executing Application: (DIAL) Options: (SIP/9413927163,60,HiL(3600000:61000:30000))
> Limit Data for this call:
> timelimit = 3600000 ms (3600.000 s)
> play_warning = 61000 ms (61.000 s)
> play_to_caller = yes
> play_to_callee = no
> warning_freq = 30000 ms (30.000 s)
> start_sound =
> warning_sound = timeleft
> end_sound =
== Using SIP RTP CoS mark 5
[Mar 3 10:36:20] WARNING[11305]: chan_sip.c:3370 __sip_xmit: sip_xmit of 0x7f2e5c00d180 (len 986) to 0.0.0.123:5060 returned -1: Invalid argument
– Called SIP/9413927163
[Mar 3 10:36:20] WARNING[6764]: chan_sip.c:3370 __sip_xmit: sip_xmit of 0x7f2e5c00d180 (len 986) to 0.0.0.123:5060 returned -1: Invalid argument
– <SIP/9413927163-0000001f>AGI Script a2billing.php completed, returning 4
== Spawn extension (a2billing, 4721984121, 2) exited non-zero on ‘SIP/9413927163-0000001f’
[Mar 3 10:36:21] WARNING[6764]: chan_sip.c:3370 __sip_xmit: sip_xmit of 0x7f2e5c00d180 (len 986) to 0.0.0.123:5060 returned -1: Invalid argument
[Mar 3 10:36:23] WARNING[6764]: chan_sip.c:3370 __sip_xmit: sip_xmit of 0x7f2e5c00d180 (len 986) to 0.0.0.123:5060 returned -1: Invalid argument

Any help is much appreciated! :smiley:
Thanks guys.

That’s suspicious right there. 0.0.0.123 is not a valid host IP address. Something is seriously mangling your SIP traffic.

Kick asterisk into debug mode (“sip set debug on”) and post the full call trace of your inbound calls.

I tried as much as possible to catch Only the incoming from PSTN here…

<— SIP read from UDP:178.63.143.236:5060 —>
INVITE sip:4721984121@voip.mydomain.com SIP/2.0
Via: SIP/2.0/UDP 178.63.143.236:5060;branch=z9hG4bK3d9b86cb;rport
Max-Forwards: 70
From: “4738622240” sip:4738622240@178.63.143.236;tag=as314995aa
To: sip:4721984121@voip.mydomain.com
Contact: sip:4738622240@178.63.143.236
Call-ID: 12b661b32e302e69390524000589f3ee@178.63.143.236
CSeq: 102 INVITE
User-Agent: Asterisk PBX 1.6.2.9-2+squeeze5
Date: Sun, 03 Mar 2013 04:20:00 GMT
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO
Supported: replaces, timer
Content-Type: application/sdp
Content-Length: 322

v=0
o=root 1688212694 1688212694 IN IP4 178.63.143.236
s=Asterisk PBX 1.6.2.9-2+squeeze5
c=IN IP4 178.63.143.236
t=0 0
m=audio 22312 RTP/AVP 0 8 18 101
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000
a=rtpmap:18 G729/8000
a=fmtp:18 annexb=no
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
a=ptime:20
a=sendrecv
<------------->
— (14 headers 14 lines) —
Sending to 178.63.143.236:5060 (NAT)
Using INVITE request as basis request - 12b661b32e302e69390524000589f3ee@178.63.143.236
Found peer ‘siptrunk’ for ‘4738622240’ from 178.63.143.236:5060
Found RTP audio format 0
Found RTP audio format 8
Found RTP audio format 18
Found RTP audio format 101
Found audio description format PCMU for ID 0
Found audio description format PCMA for ID 8
Found audio description format G729 for ID 18
Found audio description format telephone-event for ID 101
Capabilities: us - 0x6 (gsm|ulaw), peer - audio=0x10c (ulaw|alaw|g729)/video=0x0 (nothing)/text=0x0 (nothing), combined - 0x4 (ulaw)
Non-codec capabilities (dtmf): us - 0x1 (telephone-event|), peer - 0x1 (telephone-event|), combined - 0x1 (telephone-event|)
Peer audio RTP is at port 178.63.143.236:22312
Looking for 4721984121 in a2billing (domain voip.mydomain.com)
list_route: hop: sip:4738622240@178.63.143.236

<— Transmitting (NAT) to 178.63.143.236:5060 —>
SIP/2.0 100 Trying
Via: SIP/2.0/UDP 178.63.143.236:5060;branch=z9hG4bK3d9b86cb;received=178.63.143.236;rport=5060
From: “4738622240” sip:4738622240@178.63.143.236;tag=as314995aa
To: sip:4721984121@voip.mydomain.com
Call-ID: 12b661b32e302e69390524000589f3ee@178.63.143.236
CSeq: 102 INVITE
Server: Asterisk PBX 1.8.10.1~dfsg-1ubuntu1
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH
Supported: replaces, timer
Contact: sip:4721984121@192.168.1.101:5060
Content-Length: 0

<------------>
Audio is at 10708
Adding codec 0x4 (ulaw) to SDP
Adding non-codec 0x1 (telephone-event) to SDP

<— Reliably Transmitting (NAT) to 178.63.143.236:5060 —>
SIP/2.0 200 OK
Via: SIP/2.0/UDP 178.63.143.236:5060;branch=z9hG4bK3d9b86cb;received=178.63.143.236;rport=5060
From: “4738622240” sip:4738622240@178.63.143.236;tag=as314995aa
To: sip:4721984121@voip.mydomain.com;tag=as3177338c
Call-ID: 12b661b32e302e69390524000589f3ee@178.63.143.236
CSeq: 102 INVITE
Server: Asterisk PBX 1.8.10.1~dfsg-1ubuntu1
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH
Supported: replaces, timer
Contact: sip:4721984121@192.168.1.101:5060
Content-Type: application/sdp
Content-Length: 251

v=0
o=root 245110147 245110147 IN IP4 192.168.1.101
s=Asterisk PBX 1.8.10.1~dfsg-1ubuntu1
c=IN IP4 192.168.1.101
t=0 0
m=audio 10708 RTP/AVP 0 101
a=rtpmap:0 PCMU/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
a=ptime:20
a=sendrecv

<------------>
Retransmitting #1 (NAT) to 178.63.143.236:5060:
SIP/2.0 200 OK
Via: SIP/2.0/UDP 178.63.143.236:5060;branch=z9hG4bK3d9b86cb;received=178.63.143.236;rport=5060
From: “4738622240” sip:4738622240@178.63.143.236;tag=as314995aa
To: sip:4721984121@voip.mydomain.com;tag=as3177338c
Call-ID: 12b661b32e302e69390524000589f3ee@178.63.143.236
CSeq: 102 INVITE
Server: Asterisk PBX 1.8.10.1~dfsg-1ubuntu1
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH
Supported: replaces, timer
Contact: sip:4721984121@192.168.1.101:5060
Content-Type: application/sdp
Content-Length: 251

v=0
o=root 245110147 245110147 IN IP4 192.168.1.101
s=Asterisk PBX 1.8.10.1~dfsg-1ubuntu1
c=IN IP4 192.168.1.101
t=0 0
m=audio 10708 RTP/AVP 0 101
a=rtpmap:0 PCMU/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
a=ptime:20
a=sendrecv


<— SIP read from UDP:178.63.143.236:5060 —>
ACK sip:4721984121@192.168.1.101:5060 SIP/2.0
Via: SIP/2.0/UDP 178.63.143.236:5060;branch=z9hG4bK41a38205;rport
Max-Forwards: 70
From: “4738622240” sip:4738622240@178.63.143.236;tag=as314995aa
To: sip:4721984121@voip.mydomain.com;tag=as3177338c
Contact: sip:4738622240@178.63.143.236
Call-ID: 12b661b32e302e69390524000589f3ee@178.63.143.236
CSeq: 102 ACK
User-Agent: Asterisk PBX 1.6.2.9-2+squeeze5
Content-Length: 0

<------------->
— (10 headers 0 lines) —
Reliably Transmitting (NAT) to 178.63.143.236:5060:
OPTIONS sip:sip.didlogic.net SIP/2.0
Via: SIP/2.0/UDP 192.168.1.101:5060;branch=z9hG4bK47e326f2;rport
Max-Forwards: 70
From: “asterisk” sip:asterisk@192.168.1.101;tag=as73145c87
To: sip:sip.didlogic.net
Contact: sip:asterisk@192.168.1.101:5060
Call-ID: 10e92614114ebc2723a8c727413a9dcc@192.168.1.101:5060
CSeq: 102 OPTIONS
User-Agent: Asterisk PBX 1.8.10.1~dfsg-1ubuntu1
Date: Sun, 03 Mar 2013 04:20:03 GMT
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH
Supported: replaces, timer
Content-Length: 0


<— SIP read from UDP:178.63.143.236:5060 —>
SIP/2.0 404 Not Found
Via: SIP/2.0/UDP 192.168.1.101:5060;branch=z9hG4bK47e326f2;received=110.77.229.124;rport=5060
From: “asterisk” sip:asterisk@192.168.1.101;tag=as73145c87
To: sip:sip.didlogic.net;tag=as1f0bd543
Call-ID: 10e92614114ebc2723a8c727413a9dcc@192.168.1.101:5060
CSeq: 102 OPTIONS
Server: Asterisk PBX 1.6.2.9-2+squeeze5
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO
Supported: replaces, timer
Accept: application/sdp
Content-Length: 0

<------------->
— (11 headers 0 lines) —
Really destroying SIP dialog ‘10e92614114ebc2723a8c727413a9dcc@192.168.1.101:5060’ Method: OPTIONS

<— SIP read from UDP:192.168.1.1:1070 —>

<------------->
Reliably Transmitting (NAT) to 178.63.143.236:5060:
OPTIONS sip:sip.didlogic.net SIP/2.0
Via: SIP/2.0/UDP 192.168.1.101:5060;branch=z9hG4bK012de48a;rport
Max-Forwards: 70
From: “asterisk” sip:asterisk@192.168.1.101;tag=as26763f4d
To: sip:sip.didlogic.net
Contact: sip:asterisk@192.168.1.101:5060
Call-ID: 0864a2513c75b4313e66ed007f12e5ac@192.168.1.101:5060
CSeq: 102 OPTIONS
User-Agent: Asterisk PBX 1.8.10.1~dfsg-1ubuntu1
Date: Sun, 03 Mar 2013 04:20:05 GMT
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH
Supported: replaces, timer
Content-Length: 0


<— SIP read from UDP:178.63.143.236:5060 —>
SIP/2.0 404 Not Found
Via: SIP/2.0/UDP 192.168.1.101:5060;branch=z9hG4bK012de48a;received=110.77.229.124;rport=5060
From: “asterisk” sip:asterisk@192.168.1.101;tag=as26763f4d
To: sip:sip.didlogic.net;tag=as5302d755
Call-ID: 0864a2513c75b4313e66ed007f12e5ac@192.168.1.101:5060
CSeq: 102 OPTIONS
Server: Asterisk PBX 1.6.2.9-2+squeeze5
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO
Supported: replaces, timer
Accept: application/sdp
Content-Length: 0

<------------->
— (11 headers 0 lines) —
Really destroying SIP dialog ‘0864a2513c75b4313e66ed007f12e5ac@192.168.1.101:5060’ Method: OPTIONS

<— SIP read from UDP:178.63.143.236:5060 —>
BYE sip:4721984121@192.168.1.101:5060 SIP/2.0
Via: SIP/2.0/UDP 178.63.143.236:5060;branch=z9hG4bK447d8e57;rport
Max-Forwards: 70
From: “4738622240” sip:4738622240@178.63.143.236;tag=as314995aa
To: sip:4721984121@voip.mydomain.com;tag=as3177338c
Call-ID: 12b661b32e302e69390524000589f3ee@178.63.143.236
CSeq: 103 BYE
User-Agent: Asterisk PBX 1.6.2.9-2+squeeze5
X-Asterisk-HangupCause: Normal Clearing
X-Asterisk-HangupCauseCode: 16
Content-Length: 0

<------------->
— (11 headers 0 lines) —
Sending to 178.63.143.236:5060 (NAT)
Scheduling destruction of SIP dialog ‘12b661b32e302e69390524000589f3ee@178.63.143.236’ in 26304 ms (Method: BYE)

<— Transmitting (NAT) to 178.63.143.236:5060 —>
SIP/2.0 200 OK
Via: SIP/2.0/UDP 178.63.143.236:5060;branch=z9hG4bK447d8e57;received=178.63.143.236;rport=5060
From: “4738622240” sip:4738622240@178.63.143.236;tag=as314995aa
To: sip:4721984121@voip.mydomain.com;tag=as3177338c
Call-ID: 12b661b32e302e69390524000589f3ee@178.63.143.236
CSeq: 103 BYE
Server: Asterisk PBX 1.8.10.1~dfsg-1ubuntu1
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH
Supported: replaces, timer
Content-Length: 0

Problem fixed.

For those who might ever come into this problem, here is what fixed it;

Since both a2billing and asterisk is realtime, all users are stored in mysql database.
commonly enough they are stored in cc_sip_buddies.

The field ‘outboundproxy’ needs to be empty. In my case it was ‘123’ and that caused the problem.
Set it to empty and you should be good to go.

Thanks to everyone for a great forum and software.