In few lines we will describe how this dial plan should looks like. Suppose that we have two office. In first we have a few customers (they have SIP extensions) their number are 600-607. If they want to call out of office, they should dial 9+number they wants to call. There is also setup for IVR. If thay want to call another office they should dial 1+number_plan_in_that office. There is also and SIP GSM gateway. Examples for GSM gateway is on this link: GSM gateway and Asterisk

Here is example of Dial plan.

[root@asterisk1 ~]# cat /etc/asterisk/extensions.conf
TRUNK=DAHDI/G2 we setup group 2 in chan_dahdi.conf, because is G2
include => dundi-e164-canonical
include => dundi-e164-customers
include => dundi-e164-via-pstn
switch => DUNDi/e164
include => dundi-e164-local
include => dundi-e164-switch
exten => s,1,Goto(${ARG1},1)
include => dundi-e164-lookup
include => LocallCalls Calls inside a company
include => ToAnotherOffice Calls to another office
exten = s,1,Goto(voicemenu-custom,s,1) All incoming calls from pstn goes to IVR
exten = s,n,Goto(voicemenu-custom,s,1)
exten = 501,1,Goto(voicemenu-custom,s,1) All incoming call from GSM gateway goes to IVR
exten = 501,n,Goto(voicemenu-custom,s,1) 501 is SIP GSM number
exten => _6XX,1,Dial(SIP/${EXTEN},30) Calls inside company
exten => _1351X.,1,Dial(IAX2/502/9${EXTEN:4},120) If you call from outside, you should dial 1351+number_you want to call in another office, while IVR play. 351 is a protected password for calls, but second Asterisk will dial only number, because of that we have EXTEN:4. 9 is also out for that office
plancomment = DialPlan
include => LocalCalls
include => ToAnotherOffice
ignorepat => 9
exten => _9.,1,Macro(trunkdial,${TRUNK}/${EXTEN:1}) outside calls
exten => _06488658X.,1,Dial(SIP/sip_1/${EXTEN}) if you call mobile numbers you can go trough a GSM gateway, but numbers are in this range
exten => 1300,1,MeetMe(1300) conference call
exten => 700,1,Dial(SIP/sip_1/0648865800,70,Tt) short dial for user mobile
exten => _1X.,1,Dial(IAX2/502/${EXTEN:1},120) call another office
include => LocalCalls
include => ToAnotherOffice
exten = s,1,Answer
exten = s,2,Background(en/osnovni)
exten = s,3,WaitExten(5)
exten = s,4,Background(en/sekretarica) this is IVR's
exten = s,n,Dial(SIP/600,70,tT) if you don't dial a number he goes to secretary