Raspberry GSM Gateway

The idea of building my own GSM gateway came to me after travelling several times to my favourite hideaway abroad, Cambodia, over the last 6 years.

My german cellular provider for some reason doesn’t have a roaming agreement with the cambodian telcos and so my wellknown phonenumber back home was never reachable during my absences. Even if the providers would have had a roaming agreement, still an unreasonable roaming charge of about 2€ / min. for the call diversion would apply which is impracticable to me, considering the vast amount of extensive business phonecalls I expect every day.

Means, every time at Frankfurt airport when leaving for Asia I had to record an out-of-office message on the mailbox, referring callers back to the fixnet office number at least which I was able to redirect via a VoIP Provider to my cambodian cellular number. Termination of VoIP calls to the cambodian cellular networks is around 0,05€ / min. so this appeared to be a humble still viable workaround.

The voice quality of such a commercial VoIP connection though was beyond any acceptable level, huge delay, dropouts and unreliable call setup. It appeared that the VoIP call had to find it’s way to cambodia through a couple of wholesellers which caused the bad sound quality. Tried several VoIP providers, not much difference between them though, making 0,05€ / min a less good deal, all in all.

The solution for all my requirements seemed to manifest in building my own roaming network which would involve the use of two GSM gateways, one taking my german SIM in Berlin as a receiver, and one gateway in Phnom Penh as a call termination towards my cambodian GSM provider, holding a Cellcard SIM. Cellcard as many other cellular providers in emerging countries offer special rates on intra- net calls of 0,02 USD / min and below.

So far for the rough strategy. Sourcing for suitable SIP based GSM gateways, i was confronted with prices per GSM port between 200 – 400 €. For this to pay off, I would have to make a whole lot of phonecalls, I thought. So – why not try first building my own GSM gateway before spending such an amount on a black box ??

Googling a bit beamed me to a project page named chan_datacard, respectively chan_dongle which in essence is an Asterisk channel driver that drives Huawei 3G sticks. Those – beside being UMTS / HSDPA modems – are voice- SMS and USSD- capable as well. Actually a fully fledged mobilephone, just without display and keypad, mic and speaker. So all i would need there would be a host platform that runs an Asterisk and drives a Huawei dongle, one device in each country..

***

The company i work for builds some of the largest Asterisk based systems on the planet, so we all were just excited to have a look into the very opposite extreme – the currently smallest possible Asterisk box. There were some few opensource projects that theoretically could serve as a basis for building such a gateway out of a DSL router, but the cpu power of those routers did not convince me much. Else, documentation lacked alot.

Then, eventually i stumbled across the Raspberry PI and the Raspberry Asterisk project, RasPBX. Here the setup we came up with:

cambodia_raspbx_setup

This is my installation in Phnom Penh, Cambodia, the german counterpart looks much alike. In the center you find the Raspberry PI, the Huawei dongle below is served via a powered USB hub, since at GSM activity the dongle would draw too much current from the skinny builtin USB host of the RPi if being directly connected to it..

OS Installation worked without a hitch, the dongle could be succesfully connected to the RPi within one day. This is what had to be assembled:

RPi – 50€
Huawei E173 HSDPA Surfstick – 25€
Asterisk
USB Modeswitch
chan_dongle

A total BOM of 75€ (!) for a full featured GSM gateway…

***

Now when a caller in Europe calls my german GSM number, first my domestic Snom phone (right upper corner) rings, then after 5 seconds, my cambodian mobile phone gets called. As a sideffect, my cambodian friends from now on can call and SMS my german phone back at local rates of a few cents..

The connection quality over the 10.000 km spanning 64 kbps Asterisk SIP trunk between both gateways actually is so amazing that none of the callers even noticed that i was out of the country at the time !

architecture_01

Next we are going to install the identical RPi based GSM gateways at both our offices in Switzerland and Russia, VoIP- interconnected via our central (Asterisk based) PBX system in Germany, abstracting every employee’s mobilephone across the globe to a virtual extension within the company. Among many more obvious features we now are able to conduct conferences across the borders, at local call rates.

 

49 Responses to “Raspberry GSM Gateway”

  1. Calling on GSM/3G Networks | Asterisk for Raspberry Pi Says:

    [...] If you are interested in this application, you may want to read about this RPi GSM gateway [...]

  2. Stanlee Says:

    Hi, thanks for your post. i will install such a GSM-Gateway for Serbia. Because of my work I spend a lot of time there, or i have to call some plant operators few times a week. Roaming costs are terrible, 1 min incoming call costs 0,5 EUR, outbound 1,33 EUR. After a few calls i got the money back, and also my clients can call me for free anytime.

  3. Jenny Says:

    Hello,

    Any step by step guide details for this setup ?

    Thanks.

  4. Jazz Gill Says:

    Hi,Reall fascinated by your solution could you ping me your email as I spend a lot of time in Cambodia – over 5 years now – and want to know more.

    Regards, Jazz

  5. realsatire Says:

    In Russia as in many other countries you get the HUAWEI Dongle for free if you subscribe to a cheap prepaid SIM Card for mobile Internet.

    A fantastic solution :) only the packing can be done better :)

    Private GSM Roaming !

  6. Robert Says:

    Excellent article.

    If I’m understanding correctly, if you want the GSM gateway to forward calls to more than one numbers, the caller will have to dial virtual extensions via DTMF, right?

  7. Joseph_the_pi_friend Says:

    It’s great!
    Similar to some ideas that I have in mind, but for other purposes.
    In fact, I was looking for a proper GSM modem for my PIs (I bought 3 last week, 30 EUR each), and I was considering to use a mobile; actually, I was trying to use my android based, but it’s necessary to root it and mine is not happy with that.
    So, I’ll by two of these Huawei modems / mobiles!, great idea!

  8. mudkipz Says:

    I guess that a step by step guide will be really appreciated by a lot of users. :)

  9. admin Says:

    this will comming up in some days…

  10. GSM-шлюз на основе компьютера Raspberry Pi | Лучший моддинг сайт Says:

    [...] Если данный проект вас заинтересовал, то ознакомиться с ним более детально, можно посетив соответствующую заметку на ресурсе RaspberryPi.org и в блоге энтузиаста Holger’а. [...]

  11. jo Says:

    Is it possible via this gateway (using only one gw) to answer the gsm calls on the sip phone? I need to transfer all my gsm calls to the sip phone on the desk but i don’t want to pay. Thanks, looking forward the detail setup info.

  12. likecien Says:

    it’s great !

    Could you tell me how to receive sms from the e173?
    I need recive sms and auto email to my gmail it will be pushed to my ipad.

  13. Luiz Says:

    Is possible to do something like to this, but instead of redirecting directly the call, you call gsm gateway and make calls via sip?

  14. holger Says:

    Yes, it is also possible to terminate the calls coming in from the inbound GSM gateway to any phone via a SIP VoIP provider. Then you of course need only one gateway.

  15. holger Says:

    The wiki in http://wiki.e1550.mobi/doku.php?id=usage under “Receive SMS and USSD” covers most of receiving SMS. Else i found some example extensions at http://svn.dd-wrt.com/browser/src/router/chan_dongle/etc/extensions.conf?rev=20902

  16. holger Says:

    Yes thats absolutely possible. You can simply subscribe the SIP phone to the Asterisk in the gateway and redirect any incoming GSM calls to the given Phone extension.

  17. holger Says:

    We currently are updating our setup to Asterisk 11 so please be patient, we come up with a full documentation soon. For those who cannot wait googling – you should be able to find all required information here. Make sure you dont try connecting the dongle directly to the PI, only a powered USB hub will do the job.

    ***
    First, locate a suitable 3G stick, unlocked, not net- locked. It’s pretty safe to use one of the ones listed here: http://wiki.e1550.mobi/doku.php?id=requirements We prefer a Huawei E173 as it is very widespread today.

    Second install USB Modeswitch, which brings the stick from the initial Mass Storage Mode into the AT- Command Mode. What’s USB Modeswitch and how to get it: http://www.draisberghof.de/usb_modeswitch

    A good thread about individual configuration of each Dongle model is here: http://www.draisberghof.de/usb_modeswitch/bb/viewtopic.php?p=3307

    Install Asterisk 1.8 as we did succesfully. We cannot say much about Ast* 11 as we are not finished upgrading but it looks like working out of the box so far..

    Install chan_dongle from http://code.google.com/p/asterisk-chan-dongle/ and configure the channel. Write a dialplan.

    We consider posting a full image with all installations done, but please don’t pin us down on that..

  18. holger Says:

    Sure you can forward your call to other numbers within or even outside your PBX. A DISA context that gives you an internal dialtone would do the job for you. DISA extension can be easily defined in Freepbx as i have seen. Even a auto- callback function is there right next to the DISA options.

  19. holger Says:

    Thanks alot, at the last time of my visit there were no proper housings available.

    The housing you see was made out of the PCB carrier i received from RS with my first PI. It’s not too uncommon in Cambodia that you have to be able to help your self.. Two three cuts with a kitchen knife and there goes the PI housing.

  20. holger Says:

    Please read on in my earlier reply:

    http://blog.carrier-connect.com/raspberry-gsm-gateway/#comment-56

    We currently are updating our documentation.

  21. Gernot Says:

    Dear Holger,

    thank you so much for the detailed description of your setup. It is so nice to read! Your work is really well done. :)
    Somehow we did this more or less in parallel, I was working on integrating chan_dongle with RasPBX during March, but did not know about your work until you pointed me to it in April (after I finished RasPBX integration).
    I found that usb Modeswitch does not seem to be required for most newer Huawei modems. They just work out of the box without installing or configuring usb Modeswitch. Maybe the older E1550 still needs it, but I didn’t try this one myself.
    Also I have never tried chan_dongle with Asterisk 1.8, I’ve worked with Asterisk 11 right away. It seems to work perfectly fine so far.
    Manually writing the dialpan is also not required, with FreePBX it is really easy. Unless you want to do it yourself of course… :-)

    Gernot

  22. m2 Says:

    Hi,

    great solution looking forward to “how to” process and trying it myself,
    just a thought would using a Bluetooth dongle and old mobile phone make it cheaper and more universal.

    lets say that the GSM operator would not suspect we are using data dongle to make/receive loots of calls / SMS instead of using data.

  23. George Williams Says:

    Perfect solution, thank you so much for sharing!

    Just to confirm, for roaming between two countries you need two RPi’s, both running Asterisk for Raspbian and both connected to a Huawei dongle? How is the Asterisk Configuration synchronized between the two countries, or this is not necessary?

    Thank again and keep up the great work!

  24. holger Says:

    Yes, for the solution as described in our blog, you need two RPi’s with two Huawei dongles and a fairly good internet connection at each place. In cambodia a 256/256 kbps DSL works great. The Asterisk configuration is not actually synchronized between both gateways. The dialplan on each device simply forwards incoming calls on one dongle via a SIP trunk to the dongle on the other side.

  25. holger Says:

    I also was looking into some bluetooth connected setup before. Just googled chan_bluetooth and chan_mobile. Those projects dont seem to be maintained any more for a couple of years.

  26. Alex Says:

    Just checking: with this setup you pay for the call from the pi->your cellphone right?

  27. nik Says:

    Interesting. I’m also about to start working on this with my huawei e303 usb modem.

  28. FD Says:

    I have managed successfully built the system and finally came out with the possibility to make a call using usb dongle. watch the video here:

    http://youtu.be/hS5uUtUZpVI

  29. kenjie Says:

    Looking forward to a “how to” for this… been meaning to do something like this for a while now… thanks in advance

  30. binary-zero Says:

    hi,

    would you please share as what model and make of a USB hub you used ? Do i have to use the very specific mentioned on chan_dongle wiki or can I buy anyone with external power ?

  31. holger Says:

    I always used a Belkin 4 Port powered hub and since it worked right away, i did not try others yet.

    http://www.conrad.de/ce/de/product/972520/BELKIN-4PORT-USB-20-HUB-MIT-NETZTEIL?WT.ac=bs_technik

    Any other powered device should do as well, no guarantee though..

    Oh and one thing that gave me a headache for days: Never use a USB extension cord (not even 50cm) between the USB hub and the dongle as the cable’s DC resistance would cause supply voltage to drop below brownout level, where the dongle enters into strange behaviour..

  32. ctw Says:

    Hi,

    Do you have any info or are you planning to publish your dongle.conf and extensions.conf setup?

    Been trying to get this working but can only make outbound calls and receive anything in!

    Thanks.

  33. sriram r Says:

    great writeup. I am trying to do a similar project on my rasp pi by using yate instead of asterisk.. your post is a good starting point for me – thank you!

  34. holger Says:

    I don’t have a consistent, self- explaining config yet but am likely to post one later.

    Seems you got far with your own trial, so why you shouldn’t be able to receive calls ?

    Have you put a context in the dongle.conf that incoming calls are directed to ? Check example dongle.conf at

    http://wiki.e1550.mobi/doku.php?id=configuration

    What does the CLI say when calling in ?

  35. Hatem Says:

    This was very impressive and has my head spinning!

    I want to make sure that i’m understanding this correctly, forgive me for my ignorance.

    You have a setup as shown in the image above in your home location and your final destination. (your case was home: Germany and final destination: Cambodia)

    I noticed you have some land line phones connected to the device, is this the only way to use it? do you have to be hard wired? how would you go about routing that to a mobile number that is on a cell phone vs. a sim card parked in a dongle on the Pi?

    I hope i didn’t confuse you with my questioning, this is a new concept to me that I am very interested in and would like to find out more about.

    Thanks,

    Hatem

  36. holger Says:

    In my setup i as well have connected a SIP phone to the RPi, that is true. Surely you don’t need one, i just planned it like this.

    The phone is wire- connected, since the RPi has no built in WLAN. I can call the phone from the dongle(s) and vice versa, as well as from one dongle to the other.

  37. Ken Says:

    Sir I am very much interested with the sms send and receive integration into your setup. My setup is currently running for calls only with 1 dongle and I intend to add 2 more so I can cover the 3 carriers in my country.

    What I basically need is for all incoming sms from the dongles to be forwarded to my mobile fone. But since I am a newbie at coding, I would love to see some examples that I can follow and suit to my needs.

    Thank you very much for sharing.

  38. ghero Says:

    Hi,

    Can you help me please..

    i’ve managed to turn on the modem:
    Bus 001 Device 004: ID 12d1:1c05 Huawei Technologies Co., Ltd. E173s 3G broadband stick (modem on)

    but i’m unable to get the ttyUSB* device with:
    modprobe -vvv usbserial vendor=0x12d1 product=0x1c05

    thanks..

  39. ghero Says:

    Hi,

    I made some small progress.. :)

    I need some help now for real :)

    – [dongle0] Trying to connect on /dev/ttyUSB1…
    — [dongle0] Dongle has connected, initializing…
    [2013-06-12 19:06:42] ERROR[2968]: chan_dongle.c:433 do_monitor_phone: [dongle0] timedout while waiting ‘OK’ in response to ‘AT’
    — [dongle0] Error initializing Dongle
    — [dongle0] Dongle has disconnected
    [12.6.2013. 19:08:04] Igor Tomljanovic: im using ttyUSB2 for voice and ttyUSB1 for data ..

  40. Hannes Meer Says:

    Hello,

    could you tell us how you connect your raspberry (asterisk) to your pbx? through simple sip and rtp, or do you use any security layer or even vpn?

    Thank you very much and thanks for the article

  41. uzturre Says:

    Good morning:
    I would like you to explain a little more how to configure asterisk.
    Thanks

  42. Ahmed Says:

    Hi, can someone help me setup a Huawei e180 dongle? the dongle seems to be able to send and receive sms, but isnt able to send/receive voice calls.
    any help would be appreciated
    thanks

  43. nom Says:

    Hi Holger,

    your post is encouraging, can you share your step by step installation on Raspberry PI? trying to make the SMS sending and receiving work, however, not able to do so. thanks in advance,

  44. Bob Says:

    What I am looking for i something like this but than a bit different if that would be possible at all.

    In Germany you would have a pi that has a gsm antenna and would repeat the signa thru intenret.
    In the foreign country you would also have a pi and your german gsm phone. Basically your german gsm phone would register in a foreign country on the local german gsm net.

    Would it be possible to make a gsm repeater using the pi that would repeat the signal thru the internet.

  45. Hannes Says:

    Hi Holger,

    how did you establish your connection? Did you use any VPN or did you simply setup one side as a sip server?

    Holger, your project animated me making some tries, but as I see many people are waiting for some more explanation and we all would be thankfull if you could give us some more details.

    Cheers and good luck further

  46. Joao Says:

    Hi, i install everything as written but i can’t make outbound calls, but i can receive calls in the extension that i created. Can anyone help me?

  47. Marcos Saraiva Says:

    If you have a good power supply for the RPi (like the Nokia AC-10X), you don’t need a usb hub. I have a similar setup working fine.

  48. Luis Vera Says:

    Hi, can you please upload an step by step to do it? I need it for some business. I’d appreciate your help

  49. holger Says:

    Due to the large amount of different issues out there with varying hardware, software and setup, i tend to prepare and document a reference installation that would work with a specific dongle and provides most or all features that have been requested so far, like SMS relay, private roaming, GSM PBX Gateway and else. We will put together a kit with hardware and software proven to interoperate and sell it through http://www.voipango.de

    The TREX GSM Gateway Kit is coming October 2013.

    Holger

Leave a Reply

*