Raspberry Pi as a GSM2SIP (IAX2) gateway.

1) Hardware list
– Raspberry Pi
– 4GB SD card with Raspbian “wheezy” 2012-08-16
– Samsung Travel Adaptor ETA0U70XBE 5V 1A as a power supply for Raspberry Pi
– Genesys Logic USB2 4-Port Hub (05e3:0608)
– HAMA Universal Power Supply 46611 as a power supply for the USB hub
– Huawei E156G (firmware 11.609.10.00.264) *
– Huawei E1550 (firmware 11.609.18.00.00) *, **
* – with activated voice support
** – for E1550 you need also usb_modeswitch to turn on modem, because by default this dongle is detected as a usb-storage device.

With only one USB dongle Raspberry Pi works fine without an USB hub and an additional power supply.
To access Rasberry Pi console I use Logitech MK260 Wireless Desktop. I have chosen this model because of low power consumption. The USB 2.4GHz module only requires 55mA from an USB port.

2) Installation
– Boot Raspbian
– Install Asterisk package including development libraries
– Download and compile chan_dongle-1.1.r10.tgz

/etc/asterisk/dongle.conf

...
[dongle0]
context=dongle0
audio=/dev/ttyUSB2
data=/dev/ttyUSB3
imei=35xxxxxxxxxxxxx
imsi=23xxxxxxxxxxxxx

[dongle1]
context=dongle1
audio=/dev/ttyUSB5
data=/dev/ttyUSB6
imei=35yyyyyyyyyyyyy
imsi=26yyyyyyyyyyyyy

/etc/asterisk/iax.conf

...
[raspberry]
host=87.x.x.x
username=raspberry
secret=********
type=friend
qualify=yes
qualifysmoothing=yes
requirecalltoken=no
dtmf=rfc2833
dtmfmode=rfc2833
timezone=Europe/London
auth=md5
trunk=no
context=raspberry
record_out=Always
record_in=Always
deny=0.0.0.0/0.0.0.0
permit=87.x.x.x/32

/etc/asterisk/extensions.conf

...
[dongle0]
exten => ussd,1,Set(type=${USSD_TYPE})
exten => ussd,n,Set(typestr=${USSD_TYPE_STR})
exten => ussd,n,Set(ussd=${USSD})
exten => ussd,n,Set(ussd_multiline=${BASE64_DECODE(${USSD_BASE64})})
exten => ussd,n,Hangup

exten => sms,1,Set(sms=${SMS})
exten => sms,n,Set(sms_multiline=${BASE64_DECODE(${SMS_BASE64})})
exten => sms,n,Set(raw_cmgr_message=${CMGR})
exten => sms,n,Hangup

exten => s,1,Dial(IAX2/raspberry/100,120,)

exten => ANSWER,1,Hangup
exten => CANCEL,1,Hangup
exten => NOANSWER,1,Hangup
exten => BUSY,1,Hangup
exten => CONGESTION,1,Hangup
exten => CHANUNAVAIL,1,Hangup

[dongle1]
exten => ussd,1,Set(type=${USSD_TYPE})
exten => ussd,n,Set(typestr=${USSD_TYPE_STR})
exten => ussd,n,Set(ussd=${USSD})
exten => ussd,n,Set(ussd_multiline=${BASE64_DECODE(${USSD_BASE64})})
exten => ussd,n,Hangup

exten => sms,1,Set(sms=${SMS})
exten => sms,n,Set(sms_multiline=${BASE64_DECODE(${SMS_BASE64})})
exten => sms,n,Set(raw_cmgr_message=${CMGR})
exten => sms,n,Hangup

; Do not answer calls on foreign SIM cards
exten => s,1,Hangup
raspberrypi*CLI> dongle show devices
ID           Group State      RSSI Mode Submode Provider Name  Model      Firmware          IMEI             IMSI             Number    
dongle0      0     Free       27   0    0       3 UK           E156G      11.609.10.00.264  35xxxxxxxxxxxxx  23xxxxxxxxxxxxx  +44757xxxxxxx
dongle1      0     Free       8    5    4       O2 - UK        E1550      11.609.18.00.00   35yyyyyyyyyyyyy  26yyyyyyyyyyyyy  Unknown

The first call.

  == Starting Dongle/dongle0-0100000003 at dongle0,+44757xxxxxxx,1 failed so falling back to exten 's'
    -- Executing [[email protected]:1] Dial("Dongle/dongle0-0100000003", "IAX2/raspberry/100,120,") in new stack
    -- Called IAX2/raspberry/100
    -- Call accepted by 87.x.x.x (format g722)
    -- Format for call is g722
    -- IAX2/raspberry-1557 is ringing
    -- IAX2/raspberry-1557 is ringing
    -- Hungup 'IAX2/raspberry-1557'
  == Spawn extension (dongle0, s, 1) exited non-zero on 'Dongle/dongle0-0100000003'

And the first text message.

 [dongle1] Got SMS from +48505xxxxxx: 'dongle1 test message'
    -- Executing [[email protected]:1] Set("Local/[email protected];1", "sms=dongle1 test message") in new stack
    -- Executing [[email protected]:2] Set("Local/[email protected];1", "sms_multiline=dongle1 test message") in new stack
    -- Executing [[email protected]:3] Set("Local/[email protected];1", "raw_cmgr_message=+CMGR: 0,,37
07918497908952F0240B918405058118F600002190911070418014E4B7FBCC2EC740F4F29C0E6A97E7F3F0B90C") in new stack
    -- Executing [[email protected]:4] Hangup("Local/[email protected];1", "") in new stack
  == Spawn extension (dongle1, sms, 4) exited non-zero on 'Local/[email protected];1'
[    0.000000] Initializing cgroup subsys cpu
[    0.000000] Linux version 3.2.27+ ([email protected]) (gcc version 4.7.2 20120731 (prerelease) (crosstool-NG linaro-1.13.1+bzr2458 - Linaro GCC 2012.08) ) #102 PREEMPT Sat Sep 1 01:00:50 BST 2012
[    0.000000] CPU: ARMv6-compatible processor [410fb767] revision 7 (ARMv7), cr=00c5387d
[    0.000000] CPU: PIPT / VIPT nonaliasing data cache, VIPT nonaliasing instruction cache
[    0.000000] Machine: BCM2708
[    0.000000] Memory policy: ECC disabled, Data cache writeback
[    0.000000] On node 0 totalpages: 61440
[    0.000000] free_area_init_node: node 0, pgdat c0506a80, node_mem_map c05ae000
[    0.000000]   Normal zone: 480 pages used for memmap
[    0.000000]   Normal zone: 0 pages reserved
[    0.000000]   Normal zone: 60960 pages, LIFO batch:15
[    0.000000] pcpu-alloc: s0 r0 d32768 u32768 alloc=1*32768
[    0.000000] pcpu-alloc: [0] 0
[    0.000000] Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 60960
[    0.000000] Kernel command line: dma.dmachans=0x3c bcm2708_fb.fbwidth=656 bcm2708_fb.fbheight=416 bcm2708.boardrev=0x4 bcm2708.serial=0x6d65905 smsc95xx.macaddr=B8:27:EB:D6:59:05 dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait
[    0.000000] PID hash table entries: 1024 (order: 0, 4096 bytes)
[    0.000000] Dentry cache hash table entries: 32768 (order: 5, 131072 bytes)
[    0.000000] Inode-cache hash table entries: 16384 (order: 4, 65536 bytes)
[    0.000000] Memory: 240MB = 240MB total
[    0.000000] Memory: 237776k/237776k available, 7984k reserved, 0K highmem
[    0.000000] Virtual kernel memory layout:
[    0.000000]     vector  : 0xffff0000 - 0xffff1000   (   4 kB)
[    0.000000]     fixmap  : 0xfff00000 - 0xfffe0000   ( 896 kB)
[    0.000000]     vmalloc : 0xcf800000 - 0xe8000000   ( 392 MB)
[    0.000000]     lowmem  : 0xc0000000 - 0xcf000000   ( 240 MB)
[    0.000000]     modules : 0xbf000000 - 0xc0000000   (  16 MB)
[    0.000000]       .text : 0xc0008000 - 0xc04bbba8   (4815 kB)
[    0.000000]       .init : 0xc04bc000 - 0xc04dc000   ( 128 kB)
[    0.000000]       .data : 0xc04dc000 - 0xc0507100   ( 173 kB)
[    0.000000]        .bss : 0xc0507124 - 0xc05adf88   ( 668 kB)
[    0.000000] NR_IRQS:330
[    0.000000] sched_clock: 32 bits at 1000kHz, resolution 1000ns, wraps every 4294967ms
[    0.000000] timer_set_mode: unhandled mode:1
[    0.000000] timer_set_mode: unhandled mode:3
[    0.000000] Console: colour dummy device 80x30
[    0.000000] console [tty1] enabled
[    0.000915] Calibrating delay loop... 697.95 BogoMIPS (lpj=3489792)
[    0.060150] pid_max: default: 32768 minimum: 301
[    0.060625] Mount-cache hash table entries: 512
[    0.061119] Initializing cgroup subsys cpuacct
[    0.061208] Initializing cgroup subsys devices
[    0.061243] Initializing cgroup subsys freezer
[    0.061272] Initializing cgroup subsys blkio
[    0.061413] CPU: Testing write buffer coherency: ok
[    0.061761] hw perfevents: enabled with v6 PMU driver, 3 counters available
[    0.062966] devtmpfs: initialized
[    0.073205] NET: Registered protocol family 16
[    0.074778] vc_mem_connected_init: called
[    0.074850] vc_mem_update: resp 0, vcbase=0 vcsize=0 armbase=0 armsize=0
[    0.074901] vc-mem: mm_vc_mem_phys_addr = 0x00000000
[    0.074933] vc-mem: mm_vc_mem_size      = 0x00000000 (0 MiB)
[    0.075399] hw-breakpoint: found 6 breakpoint and 1 watchpoint registers.
[    0.075453] hw-breakpoint: maximum watchpoint size is 4 bytes.
[    0.075490] mailbox: Broadcom VideoCore Mailbox driver
[    0.075584] bcm2708_vcio: mailbox at f200b880
[    0.075688] bcm_power: Broadcom power driver
[    0.075726] bcm_power_open() -> 0
[    0.075751] bcm_power_request(0, 8)
[    0.576432] bcm_mailbox_read -> 00000080, 0
[    0.576470] bcm_power_request -> 0
[    0.576495] Serial: AMBA PL011 UART driver
[    0.576652] dev:f1: ttyAMA0 at MMIO 0x20201000 (irq = 83) is a PL011 rev3
[    0.895694] console [ttyAMA0] enabled
[    0.920168] bio: create slab  at 0
[    0.925359] SCSI subsystem initialized
[    0.929458] usbcore: registered new interface driver usbfs
[    0.935078] usbcore: registered new interface driver hub
[    0.940695] usbcore: registered new device driver usb
[    0.946629] Switching to clocksource stc
[    0.951001] FS-Cache: Loaded
[    0.954178] CacheFiles: Loaded
[    0.970580] NET: Registered protocol family 2
[    0.975484] IP route cache hash table entries: 2048 (order: 1, 8192 bytes)
[    0.983563] TCP established hash table entries: 8192 (order: 4, 65536 bytes)
[    0.991068] TCP bind hash table entries: 8192 (order: 3, 32768 bytes)
[    0.997711] TCP: Hash tables configured (established 8192 bind 8192)
[    1.004129] TCP reno registered
[    1.007296] UDP hash table entries: 256 (order: 0, 4096 bytes)
[    1.013205] UDP-Lite hash table entries: 256 (order: 0, 4096 bytes)
[    1.019988] NET: Registered protocol family 1
[    1.025177] RPC: Registered named UNIX socket transport module.
[    1.031310] RPC: Registered udp transport module.
[    1.036035] RPC: Registered tcp transport module.
[    1.040783] RPC: Registered tcp NFSv4.1 backchannel transport module.
[    1.047504] bcm2708_dma: DMA manager at cf808000
[    1.052302] bcm2708_gpio: bcm2708_gpio_probe c04e3c18
[    1.057756] vc-mem: Videocore memory driver
[    1.062760] audit: initializing netlink socket (disabled)
[    1.068245] type=2000 audit(0.740:1): initialized
[    1.184526] VFS: Disk quotas dquot_6.5.2
[    1.188674] Dquot-cache hash table entries: 1024 (order 0, 4096 bytes)
[    1.196256] FS-Cache: Netfs 'nfs' registered for caching
[    1.202566] msgmni has been set to 464
[    1.208377] io scheduler noop registered
[    1.212484] io scheduler deadline registered (default)
[    1.217792] io scheduler cfq registered
[    1.221951] BCM2708FB: registering framebuffer ([email protected])
[    1.228046] bcm2708_fb_set_par info(ce8b5000) 656x416 (656x416), 0, 16
[    1.245778] BCM2708FB: start = cf900000,4f585000 width=656, height=416, bpp=16, pitch=1312 size=545792 success=0
[    1.249645] Console: switching to colour frame buffer device 82x26
[    1.284131] BCM2708FB: register framebuffer (0)
[    1.291478] kgdb: Registered I/O driver kgdboc.
[    1.307708] brd: module loaded
[    1.317992] loop: module loaded
[    1.324310] vcos: [1]: vchiq_init_state: slot_zero = 0xffd80000, is_master = 0
[    1.334700] vcos: [1]: vchiq_init_state: called
[    1.342431] vcos: [1]: vchiq: initialised - version 2 (min 2), device 252.0
[    1.352413] usbcore: registered new interface driver smsc95xx
[    1.360491] cdc_ncm: 04-Aug-2011
[    1.366178] usbcore: registered new interface driver cdc_ncm
[    1.374168] dwc_otg: version 3.00a 10-AUG-2012 (platform bus)
[    1.582386] Core Release: 2.80a
[    1.587747] Setting default values for core params
[    1.594921] Finished setting default values for core params
[    1.802935] Using Buffer DMA mode
[    1.808550] Periodic Transfer Interrupt Enhancement - disabled
[    1.816740] Multiprocessor Interrupt Enhancement - disabled
[    1.824786] OTG VER PARAM: 0, OTG VER FLAG: 0
[    1.831473] Dedicated Tx FIFOs mode
[    1.837319] dwc_otg: Microframe scheduler enabled
[    1.837372] dwc_otg bcm2708_usb: DWC OTG Controller
[    1.844576] dwc_otg bcm2708_usb: new USB bus registered, assigned bus number 1
[    1.854102] dwc_otg bcm2708_usb: irq 75, io mem 0x00000000
[    1.861873] Init: Port Power? op_state=1
[    1.867908] Init: Power Port (0)
[    1.873440] usb usb1: New USB device found, idVendor=1d6b, idProduct=0002
[    1.882505] usb usb1: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[    1.891991] usb usb1: Product: DWC OTG Controller
[    1.898875] usb usb1: Manufacturer: Linux 3.2.27+ dwc_otg_hcd
[    1.906823] usb usb1: SerialNumber: bcm2708_usb
[    1.914406] hub 1-0:1.0: USB hub found
[    1.920301] hub 1-0:1.0: 1 port detected
[    1.927051] dwc_otg: FIQ disabled
[    1.927080] Module dwc_common_port init
[    1.927425] usbcore: registered new interface driver uas
[    1.934943] Initializing USB Mass Storage driver...
[    1.942257] usbcore: registered new interface driver usb-storage
[    1.950363] USB Mass Storage support registered.
[    1.957351] usbcore: registered new interface driver libusual
[    1.965674] mousedev: PS/2 mouse device common for all mice
[    1.973444] cpuidle: using governor ladder
[    1.979639] cpuidle: using governor menu
[    1.985739] sdhci: Secure Digital Host Controller Interface driver
[    1.994083] sdhci: Copyright(c) Pierre Ossman
[    2.000598] sdhci: Enable low-latency mode
[    2.006833] bcm_power_open() -> 1
[    2.013470] Registered led device: mmc0::
[    2.014897] mmc0: SDHCI controller on BCM2708_Arasan [platform] using platform's DMA
[    2.027111] mmc0: BCM2708 SDHC host at 0x20300000 DMA 2 IRQ 77
[    2.035277] sdhci-pltfm: SDHCI platform and OF driver helper
[    2.044520] Registered led device: led0
[    2.044914] usbcore: registered new interface driver usbhid
[    2.052727] usbhid: USB HID core driver
[    2.060002] TCP cubic registered
[    2.065557] Initializing XFRM netlink socket
[    2.074251] NET: Registered protocol family 17
[    2.084142] Registering the dns_resolver key type
[    2.093320] VFP support v0.3: implementor 41 architecture 1 part 20 variant b rev 5
[    2.114716] registered taskstats version 1
[    2.121327] Indeed it is in host mode hprt0 = 00021501
[    2.128956] drivers/rtc/hctosys.c: unable to open rtc device (rtc0)
[    2.151326] Waiting for root device /dev/mmcblk0p2...
[    2.177110] mmc0: problem reading SD Status register.
[    2.194557] mmc0: new high speed SDHC card at address 0007
[    2.211425] mmcblk0: mmc0:0007 SD04G 3.80 GiB
[    2.231906]  mmcblk0: p1 p2
[    2.299393] EXT4-fs (mmcblk0p2): mounted filesystem with ordered data mode. Opts: (null)
[    2.312219] VFS: Mounted root (ext4 filesystem) on device 179:2.
[    2.321470] Freeing init memory: 128K
[    2.370845] usb 1-1: new high-speed USB device number 2 using dwc_otg
[    2.380111] Indeed it is in host mode hprt0 = 00001101
[    2.601103] usb 1-1: New USB device found, idVendor=0424, idProduct=9512
[    2.610633] usb 1-1: New USB device strings: Mfr=0, Product=0, SerialNumber=0
[    2.621364] hub 1-1:1.0: USB hub found
[    2.627993] hub 1-1:1.0: 3 ports detected
[    2.911075] usb 1-1.1: new high-speed USB device number 3 using dwc_otg
[    3.041386] usb 1-1.1: New USB device found, idVendor=0424, idProduct=ec00
[    3.051228] usb 1-1.1: New USB device strings: Mfr=0, Product=0, SerialNumber=0
[    3.065202] smsc95xx v1.0.4
[    3.136198] smsc95xx 1-1.1:1.0: eth0: register 'smsc95xx' at usb-bcm2708_usb-1.1, smsc95xx USB 2.0 Ethernet, b8:27:eb:d6:59:05
[    3.251045] usb 1-1.3: new high-speed USB device number 4 using dwc_otg
[    3.382790] usb 1-1.3: New USB device found, idVendor=05e3, idProduct=0608
[    3.400872] usb 1-1.3: New USB device strings: Mfr=0, Product=1, SerialNumber=0
[    3.420935] usb 1-1.3: Product: USB2.0 Hub
[    3.436289] hub 1-1.3:1.0: USB hub found
[    3.451310] hub 1-1.3:1.0: 4 ports detected
[    3.741311] usb 1-1.3.1: new high-speed USB device number 5 using dwc_otg
[    3.882314] usb 1-1.3.1: New USB device found, idVendor=12d1, idProduct=140c
[    3.900864] usb 1-1.3.1: New USB device strings: Mfr=3, Product=2, SerialNumber=0
[    3.927047] usb 1-1.3.1: Product: HUAWEI Mobile
[    3.940861] usb 1-1.3.1: Manufacturer: HUAWEI Technology
[    3.985059] scsi4 : usb-storage 1-1.3.1:1.4
[    3.999604] scsi5 : usb-storage 1-1.3.1:1.5
[    4.081721] usb 1-1.3.4: new high-speed USB device number 6 using dwc_otg
[    4.222228] usb 1-1.3.4: New USB device found, idVendor=12d1, idProduct=14ac
[    4.250862] usb 1-1.3.4: New USB device strings: Mfr=4, Product=3, SerialNumber=0
[    4.290810] usb 1-1.3.4: Product: HUAWEI Mobile
[    4.297787] usb 1-1.3.4: Manufacturer: HUAWEI Technology
[    4.350508] scsi6 : usb-storage 1-1.3.4:1.5
[    4.368697] scsi7 : usb-storage 1-1.3.4:1.6
[    4.875518] usbcore: registered new interface driver usbserial
[    4.919785] cdc_ether 1-1.3.4:1.1: wwan0: register 'cdc_ether' at usb-bcm2708_usb-1.3.4, Mobile Broadband Network Device, 02:50:f3:00:00:00
[    4.994498] scsi 4:0:0:0: CD-ROM            HUAWEI   Mass Storage     2.31 PQ: 0 ANSI: 2
[    5.037095] scsi 5:0:0:0: Direct-Access     HUAWEI   MMC Storage      2.31 PQ: 0 ANSI: 2
[    5.098039] USB Serial support registered for generic
[    5.098880] sd 5:0:0:0: [sda] Attached SCSI removable disk
[    5.128596] usbcore: registered new interface driver usbserial_generic
[    5.128633] usbserial: USB Serial Driver core
[    5.132709] usbcore: registered new interface driver cdc_ether
[    5.166165] USB Serial support registered for GSM modem (1-port)
[    5.166554] option 1-1.3.1:1.0: GSM modem (1-port) converter detected
[    5.208402] usb 1-1.3.1: GSM modem (1-port) converter now attached to ttyUSB0
[    5.208525] option 1-1.3.1:1.1: GSM modem (1-port) converter detected
[    5.210996] usb 1-1.3.1: GSM modem (1-port) converter now attached to ttyUSB1
[    5.211116] option 1-1.3.1:1.2: GSM modem (1-port) converter detected
[    5.211679] usb 1-1.3.1: GSM modem (1-port) converter now attached to ttyUSB2
[    5.211782] option 1-1.3.1:1.3: GSM modem (1-port) converter detected
[    5.212290] usb 1-1.3.1: GSM modem (1-port) converter now attached to ttyUSB3
[    5.212615] option 1-1.3.4:1.0: GSM modem (1-port) converter detected
[    5.296178] usb 1-1.3.4: GSM modem (1-port) converter now attached to ttyUSB4
[    5.296518] option 1-1.3.4:1.3: GSM modem (1-port) converter detected
[    5.297169] usb 1-1.3.4: GSM modem (1-port) converter now attached to ttyUSB5
[    5.297294] option 1-1.3.4:1.4: GSM modem (1-port) converter detected
[    5.297786] usb 1-1.3.4: GSM modem (1-port) converter now attached to ttyUSB6
[    5.298093] usbcore: registered new interface driver option
[    5.298106] option: v0.7.2:USB Driver for GSM modems
[    5.364591] scsi 6:0:0:0: CD-ROM            HUAWEI   Mass Storage     2.31 PQ: 0 ANSI: 2
[    5.454687] scsi 7:0:0:0: Direct-Access     HUAWEI   MMC Storage      2.31 PQ: 0 ANSI: 2
[    5.464971] sd 7:0:0:0: [sdb] Attached SCSI removable disk
[    8.047232] sr0: scsi-1 drive
[    8.165394] cdrom: Uniform CD-ROM driver Revision: 3.20
[    8.323734] sr 4:0:0:0: Attached scsi CD-ROM sr0
[    8.341457] sr1: scsi-1 drive
[    8.464353] sr 6:0:0:0: Attached scsi CD-ROM sr1
[   15.333765] EXT4-fs (mmcblk0p2): re-mounted. Opts: (null)
[   16.125477] ### snd_bcm2835_alsa_probe c04e4430 ############### PROBING FOR bcm2835 ALSA device (0):(1) ###############
[   16.141351] Creating card...
[   16.146728] Creating device/chip ..
[   16.153168] Adding controls ..
[   16.168098] Registering card ....
[   16.175549] bcm2835 ALSA CARD CREATED!
[   16.191662] ### BCM2835 ALSA driver init OK ###
[   16.379941] NET: Registered protocol family 10
[   23.905528] ADDRCONF(NETDEV_UP): eth0: link is not ready
[   25.557944] ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
[   25.560117] smsc95xx 1-1.1:1.0: eth0: link up, 100Mbps, full-duplex, lpa 0x45E1
[   34.270725] sched: RT throttling activated
[   34.340757] wwan0: no IPv6 routers present
[   36.123865] Adding 102396k swap on /var/swap.  Priority:-1 extents:1 across:102396k SS