I recently got into VoIP and phones. After a really quick setup of a very glorified home intercom setup, I wanted to make outbound calls and receive incoming calls from outside the safe haven of my LAN. I looked online for either free or cheap SIP trunks and either could not found any that I could afford or ones with a local phone number. Then I found out about Yeastar TG100 - a GSM gateway.

A photo of TG100

One free SIM card away (from bonbon) and we can start! After plugging in the device you need to switch it to DHCP. Change your computer’s IP and subnet mask to match the default one of the device and follow the somewhat intuitive but very “Chineseque” UI. The default username password combo is admin/password.

Configuring trunks

The TG100 runs Asterisk as well and all it does it create a SIP account for you to use as a trunk. You have two active by default. You can find them in: Gateway > VoIP trunk.

I left only one (20001) and removed the second one. The default username and password combo is: 20001/pincode20001. Don’t forget to change them! That’s it - at this point, you can connect with your SIP client and try this out. I used Telephone to test out the gateway.

Screengrab of Telephone in action

Configuring Asterisk

I’m going to assume you don’t have anything set up and that you just installed Asterisk. If you do be careful to place the needed parts of the configuration in the correct place.

For the following guide my setup details are the following:

  • Gateway IP: 10.10.5.130
  • Gateway SIP account: 20001
  • Gateway SIP password: pincode20001

Remove the default sip configuration at /etc/asterisk/sip.conf and replace it with the following snippet:

[general]
register = 20001:[email protected]/20001
context=public
allowoverlap=no

[tgprovider]
type=friend
secret=pincode20001
username=20001
host=10.10.5.130
dtmfmode=rfc2833
canreinvite=no
disallow=all
allow=ulaw
allow=alaw
allow=gsm
insecure=port,invite
fromdomain=10.10.5.130
context=incoming

udpbindaddr=0.0.0.0            
transport=udp
srvlookup=yes

Be careful to replace my details with yours. Here we just set up the connection to our GSM gateway. Once this is placed in if you restart Asterisk you should be able to see that it connected. You can see that on the TG100 admin page.

Next up are the users. Remove the default configuration and replace it with our snippet. The file is /etc/asterisk/users.conf.

[test-client]
fullname = Test Client
secret = 1234
hassip = yes
context = users
host = dynamic

I added only one user for now. This user is going to be used for incoming calls as well. Next up is configuring the extensions and allowing our users to receive and place calls.

Remove and replace the /etc/asterisk/extensions.conf with this snippet:

[general]
static=yes
writeprotect=no
clearglobalvars=no

[users]
exten => 1001,1,Dial(SIP/test-client)

exten => _9XXXX.,1,Log(NOTICE, Dialing out from ${CALLERID(all)} to ${EXTEN:1} through TG Provider)
exten => _9XXXX.,n,Dial(SIP/tgprovider/${EXTEN:1},60)
exten => _9XXXX.,n,Playtones(congestion)
exten => _9XXXX.,n,Hangup()

[incoming]
exten => 20001,1,Log(NOTICE, Incoming call from ${CALLERID(all)})
exten => 20001,n,Dial(SIP/test-client)
exten => 20001,n,Hangup()

There are two things to note here!

First, we have [users] here we place our “local” phones and a way for them to dial out. On my system, if you want to dial out you have to prefix your phone number with 9.

Next is [incoming]. Here is where we specify how our phone system is going to act when it gets rang. For this blog post, we are only going to dial our 1002 extension and call it a day.

Connect with your SIP client and test everything out!

Multiple phones

Once we have everything working with our basic setup we should add more phones. Let’s add one more extension to the setup. Append the following lines to /etc/asterisk/users.conf:

[test-client2]
fullname = Test Client 2
secret = 1234
hassip = yes
context = users
host = dynamic

The phone can now login but we have to add the extension as well to the /etc/extensions.conf:

[users]
exten => 1001,1,Dial(SIP/test-client)
exten => 1002,1,Dial(SIP/test-client2)

If you reload asterisk at this point you can now place calls from one extension from another, and you can also place outgoing calls. But - only 1001 will ring on the outside call. Let’s make them all ring. We are going to use queues for this.

Remove and replace the /etc/asterisk/queueus.conf file with the following:

[users-queue]
context = users
strategy = ringall
timeout = 100
retry = 5
maxlen = 1
joinempty = yes
leavewhenempty=yes
reportholdtime = yes

member => SIP/test-client
member => SIP/test-client2

Note the contex and member lines. Modify them to match your setup. I’ve also added a neat reportholdtime that will tell you for how long someone has waited for you to pick up.

Only thing left is to modify the [incoming] in our extensions.conf:

[incoming]
exten => 20001,1,Log(NOTICE, Incoming call from ${CALLERID(all)})
exten => 20001,n,Set(QUEUE_PRIO=10)
exten => 20001,n,Queue(users-queue)
exten => 20001,n,Hangup()

That’s it. Try calling your new number and see what happens!