With SIP, the signaling is done via SIP and the digitized audio is sent via a different protocol, RTP. The SIP and RTP can and often are sent to different IP addresses. Thats normally not a problem, as long as the IP addresses are all reachable..
Whats happening in your situation, is something like this:
PBX2 sends a SIP INVITE to PBX1. Included in that INVITE is information about where to send the audio. PBX2 specifies its own IP address. Since its IP address is reachable from PBX1, calls between the two work.
Now, when the callee is an outside line, PBX1 sends its own INVITE to your provider, and passes on in that INVITE the information about where to send the audio (ie, the IP address of PBX2) If both PBXs were on public IPs, this would be fine. Since they are not both reachable from the outside, you need to modify the behavior of PBX1
On PBX1, in your sip.conf
file, there should be a peer configuration for PBX2. In that peer configuration, you need to add the following line:
canreinvite=no
(On more recent versions of asterisk, you would use directmedia=no
instead.)
This will cause PBX1 to stay in the media path whenever it is involved with a call with PBX2. In otherwords, when you call the outside world, PBX1 will give your provider its own IP address for where to send the audio, it will then proxy that audio, and send it on to PBX2.
Hope this helps!
I've done something similar and like the other submitter, I used a database. Instead of using the built int DB functionality, I used cmd MySQL. This was so I could write a web page that interacts with the same DB AND my DBA could do cross DB selects between this "Directory" table and the MySQL CDR.
In my example, I setup a table with 4 fields. id
(auto_increment int), number
(the phone number), name
(The name of user), ban
(an int that defaults to 0). The example does 2 things, 1- it looks up name from the DB and sets that as the caller id (Since our POTS line doesn't communicate that) 2- It looks up to see if ban
is set to 1, and blocks the call.
exten => s,1,Answer
exten => s,n,NoOp("Caller ID IS: ${CALLERID(number)}")
exten => s,n,MYSQL(Connect connid HOST USER PASSWORD database)
exten => s,n,MYSQL(Query resultid ${connid} SELECT name,ban FROM directory WHERE number='${CALLERID(number)}')
exten => s,n,MYSQL(Fetch fetchid ${resultid} name ban)
exten => s,n,NoOp("We found: ${name} ${ban}")
exten => s,n,MYSQL(Clear ${resultid})
exten => s,n,MYSQL(Disconnect ${connid});
exten => s,n,Set(CALLERID(name)=${name})
exten => s,10,NoOp()
exten => s,n,GotoIf($["${ban}" = "1"]?wedontlikeyou,s,1)
exten => s,n,Goto(mainmenu,s,1)
After this you'd have your [mainmenu] and [wedontlikeyou]. The later is your ban, it could be a simple hangup, error message, what ever you want. My preference is Congestion() since that tends to make people think the phone number is out of service.
Best Answer
I was looking for this also. You want "RDNIS"
http://www.voip-info.org/wiki/view/RDNIS
Just look at that to determine what numbers were involved.