Saturday, March 28, 2009

Running my own SMS Service with Kannel and HUAWEI E180

pencil icon, that"s clickable to start editing the post

Mobile Services are becomming more and more common. Seven years ago I had the opportunity to develop some simpel SMS services, and SMS services is still the most common form of Mobile Services, though the mobile web is picking up momentum as well as custom Mobile Aplications. I decided to have a look at Mobile Services and to start with building a simple SMS Service. This blog post vil cover the basic setup and a later post the service part itself (though it's fairly easy).

Back in 2002 the company I worked for used both a commercial SMSC with billing etc., but we also ran our own SMSC to receive data carried by SMS. For our own SMSC we used Kannel which was quite easy to setup and run. I was please to see the Kannel project is still running.

I started by downloading the lastest stable release (version 1.4.3). Installing on my Fedora 10 Linux distribution was an easy classic ./configure, make, make install. The binary distribution comes with a sample SMSC configuration in the gw/smskannel.conf file. I only needed to update it with my local settings which involved figuring out the way to hook it up to my modem (the only part that was a bit problematic back then with a serial interface).

The Huawei E180 Modem

I have a Mobile Broadband ISP (flatrate) that comes with a USB modem (3G). The modem has the name E180, and can be seen on the Huawei device website HUAWEI E180 - HSPA USB Stick. The short specification list is: Support 2Mbps (5.76Mbps ready) HSUPA and 7.2Mbps HSDPA services Support SMS and Voice services. To find the manual is quite har since it's not available from Huawei's own support site, so through Google I found it [PDF] at the South African company Maredi's website. It carries the subtitle as flexiable as wings and it certainly is easy to use on both Linux and Windows, though I'm not sure I really like the metaphor on airplane wings.

After I insert the modem into a USB port the messages log showes something like:

Mar 28 07:47:11 kannel kernel: usb 2-1: new high speed USB device using ehci_hcd and address 3
Mar 28 07:47:11 kannel kernel: usb 2-1: configuration #1 chosen from 1 choice                 
Mar 28 07:47:11 kannel kernel: scsi3 : SCSI emulation for USB Mass Storage devices            
Mar 28 07:47:11 kannel kernel: scsi4 : SCSI emulation for USB Mass Storage devices            
Mar 28 07:47:11 kannel kernel: usb 2-1: New USB device found, idVendor=12d1, idProduct=1003   
Mar 28 07:47:11 kannel kernel: usb 2-1: New USB device strings: Mfr=2, Product=1, SerialNumber=0
Mar 28 07:47:11 kannel kernel: usb 2-1: Product: HUAWEI Mobile                                  
Mar 28 07:47:11 kannel kernel: usb 2-1: Manufacturer: HUAWEI Technology                         
Mar 28 07:47:11 kannel kernel: usb 2-1: USB disconnect, address 3                               
Mar 28 07:47:11 kannel pulseaudio[3309]: module-hal-detect.c: Error getting capability: org.freedesktop.Hal.NoSuchDevice: No device with id /org/freedesktop/Hal/devices/usb_device_ffffffff_ffffffff_noserial_scsi_host                                     
Mar 28 07:47:11 kannel pulseaudio[3309]: module-hal-detect.c: Error getting capability: org.freedesktop.Hal.NoSuchDevice: No device with id /org/freedesktop/Hal/devices/usb_device_ffffffff_ffffffff_noserial_0_scsi_host                                   
Mar 28 07:47:17 kannel kernel: usb 2-1: new high speed USB device using ehci_hcd and address 4                                 
Mar 28 07:47:17 kannel kernel: usb 2-1: configuration #1 chosen from 1 choice                                                  
Mar 28 07:47:17 kannel kernel: usb-storage: probe of 2-1:1.0 failed with error -5                                              
Mar 28 07:47:17 kannel kernel: usb-storage: probe of 2-1:1.1 failed with error -5                                              
Mar 28 07:47:18 kannel kernel: scsi7 : SCSI emulation for USB Mass Storage devices                                             
Mar 28 07:47:19 kannel kernel: scsi8 : SCSI emulation for USB Mass Storage devices                                             
Mar 28 07:47:19 kannel kernel: usb 2-1: New USB device found, idVendor=12d1, idProduct=1003                                    
Mar 28 07:47:19 kannel kernel: usb 2-1: New USB device strings: Mfr=2, Product=1, SerialNumber=0
Mar 28 07:47:19 kannel kernel: usb 2-1: Product: HUAWEI Mobile
Mar 28 07:47:19 kannel kernel: usb 2-1: Manufacturer: HUAWEI Technology
Mar 28 07:47:19 kannel kernel: usbcore: registered new interface driver usbserial
Mar 28 07:47:19 kannel kernel: usbserial: USB Serial support registered for generic
Mar 28 07:47:19 kannel kernel: usbcore: registered new interface driver usbserial_generic
Mar 28 07:47:19 kannel kernel: usbserial: USB Serial Driver core
Mar 28 07:47:19 kannel kernel: usbserial: USB Serial support registered for GSM modem (1-port)
Mar 28 07:47:19 kannel kernel: option 2-1:1.0: GSM modem (1-port) converter detected
Mar 28 07:47:19 kannel kernel: usb 2-1: GSM modem (1-port) converter now attached to ttyUSB0
Mar 28 07:47:19 kannel kernel: option 2-1:1.1: GSM modem (1-port) converter detected
Mar 28 07:47:19 kannel kernel: usb 2-1: GSM modem (1-port) converter now attached to ttyUSB1
Mar 28 07:47:19 kannel kernel: usbcore: registered new interface driver option
Mar 28 07:47:19 kannel kernel: option: USB Driver for GSM modems: v0.7.2
Mar 28 07:47:23 kannel kernel: scsi 7:0:0:0: CD-ROM            HUAWEI   Mass Storage     2.31 PQ: 0 ANSI: 2
Mar 28 07:47:23 kannel kernel: sr0: scsi-1 drive
Mar 28 07:47:23 kannel kernel: Uniform CD-ROM driver Revision: 3.20
Mar 28 07:47:23 kannel kernel: sr 7:0:0:0: Attached scsi generic sg2 type 5
Mar 28 07:47:24 kannel kernel: scsi 8:0:0:0: Direct-Access     HUAWEI   SD Storage       2.31 PQ: 0 ANSI: 2
Mar 28 07:47:24 kannel kernel: sd 8:0:0:0: [sdc] Attached SCSI removable disk
Mar 28 07:47:24 kannel kernel: sd 8:0:0:0: Attached scsi generic sg3 type 0
Mar 28 07:47:25 kannel NetworkManager:   (ttyUSB0): detected GSM modem via HAL capabilities
Mar 28 07:47:25 kannel NetworkManager:   (ttyUSB0): new Modem device (driver: 'option')
Mar 28 07:47:25 kannel NetworkManager:   (ttyUSB0): exported as /org/freedesktop/Hal/devices/usb_device_12d1_1003_noserial_if0_serial_usb_0
Mar 28 07:47:29 kannel NetworkManager:   (ttyUSB0): device state change: 1 -> 2
Mar 28 07:47:29 kannel NetworkManager:   (ttyUSB0): deactivating device (reason: 2).

Configure and run Bearerbox

The bearerbox part of the example configuration with just the needed changes, configuring the bearerbox and the two SMSC connections, the first one the fake SMSC and the other one my virtual SMSC based on my Huawei E180 modem:

# Needed - otherwise Kannel Bearerbox could not configure the modem correctly
include = doc/examples/modems.conf                                       

#---------------------------------------------                           
# CORE                                                                   
#---------------------------------------------                           
group = core
admin-port = 13000
smsbox-port = 13001
admin-password = bar
box-deny-ip = "*.*.*.*"      
box-allow-ip = "127.0.0.1"   

#---------------------------------------------
# SMSC CONNECTIONS                            
#                                             
# SMSC connections are created in bearerbox and they handle SMSC specific
# protocol and message relying. You need these to actually receive and send
# messages to handset, but can use GSM modems as virtual SMSCs             

# This is a fake smsc connection, _only_ used to test the system and services.
# It really cannot relay messages to actual handsets!                         
group = smsc
smsc = fake 
smsc-id = FAKE
port = 10000  
connect-allow-ip = 127.0.0.1


# My own 'virtual' SMSC with the HUAWEI E169 
group = smsc
smsc = at   
modemtype = auto
device = /dev/ttyUSB1
my-number = [TheTelephoneNumberOnTheSIM]
log-level = 0        
pin = [ThePINofTheSIM]

The Bearerbox is started with /opt/kannel-1.4.3/sbin/bearerbox -v 1 /home/kannel/Download/gateway-1.4.3/gw/smskannel.conf and the output is:

2009-03-28 07:55:26 [4193] [0] INFO: Debug_lvl = 1, log_file = , log_lvl = 0
2009-03-28 07:55:26 [4193] [0] WARNING: DLR: using default 'internal' for storage type.
2009-03-28 07:55:26 [4193] [0] INFO: DLR using storage type: internal
2009-03-28 07:55:26 [4193] [0] INFO: HTTP: Opening server at port 13000.
2009-03-28 07:55:26 [4193] [0] INFO: BOXC: 'smsbox-max-pending' not set, using default (100).
2009-03-28 07:55:26 [4193] [0] INFO: Set SMS resend frequency to 60 seconds.
2009-03-28 07:55:26 [4193] [0] INFO: SMS resend retry set to unlimited.
2009-03-28 07:55:26 [4193] [0] INFO: DLR rerouting for smsc id  disabled.
2009-03-28 07:55:26 [4193] [0] INFO: DLR rerouting for smsc id <(null)> disabled.
2009-03-28 07:55:26 [4193] [0] INFO: AT2[/dev/ttyUSB1]: configuration doesn't show modemtype. will autodetect
2009-03-28 07:55:26 [4193] [0] INFO: ----------------------------------------
2009-03-28 07:55:26 [4193] [0] INFO: Kannel bearerbox II version 1.4.3 starting
2009-03-28 07:55:26 [4193] [0] INFO: MAIN: Start-up done, entering mainloop
2009-03-28 07:55:26 [4193] [7] INFO: AT2[/dev/ttyUSB1]: opening device
2009-03-28 07:55:27 [4193] [7] INFO: AT2[/dev/ttyUSB1]: speed set to 115200
2009-03-28 07:55:29 [4193] [7] INFO: AT2[/dev/ttyUSB1]: Closing device
2009-03-28 07:55:29 [4193] [7] INFO: AT2[/dev/ttyUSB1]: detect speed is 115200
2009-03-28 07:55:29 [4193] [7] INFO: AT2[/dev/ttyUSB1]: opening device
2009-03-28 07:55:30 [4193] [7] INFO: AT2[/dev/ttyUSB1]: speed set to 115200
2009-03-28 07:55:32 [4193] [7] INFO: AT2[/dev/ttyUSB1]: Closing device
2009-03-28 07:55:32 [4193] [7] INFO: AT2[/dev/ttyUSB1]: opening device
2009-03-28 07:55:32 [4193] [7] INFO: AT2[/dev/ttyUSB1]: Logging in
2009-03-28 07:55:33 [4193] [7] INFO: AT2[/dev/ttyUSB1]: init device
2009-03-28 07:55:33 [4193] [7] INFO: AT2[/dev/ttyUSB1]: speed set to 115200
2009-03-28 07:55:33 [4193] [7] ERROR: AT2[/dev/ttyUSB1]: Generic error: ERROR
2009-03-28 07:55:33 [4193] [7] INFO: AT2[/dev/ttyUSB1]: cannot enable hardware handshake
2009-03-28 07:55:34 [4193] [7] INFO: AT2[/dev/ttyUSB1]: AT SMSC successfully opened.

Configuring and running the Smsbox

The Userguide has the complete options for SMSBOX configruation and the example configuration is just fine:

#---------------------------------------------
# SMSBOX SETUP                                
#                                             
# Smsbox(es) do higher-level SMS handling after they have been received from
# SMS centers by bearerbox, or before they are given to bearerbox for delivery

group = smsbox
bearerbox-host = 127.0.0.1
sendsms-port = 13013      
global-sender = 13013     
#log-file = "/tmp/smsbox.log"   
#log-level = 0                  

To use the SMSC for pushing SMS the SendSMS-user configuration is needed:

#---------------------------------------------
# SEND-SMS USERS
#
# These users are used when Kannel smsbox sendsms interface is used to
# send PUSH sms messages, i.e. calling URL like
# http://kannel.machine:13013/cgi-bin/sendsms?username=tester&password=foobar...

group = sendsms-user
username = tester
password = foobar
#user-allow-ip = ""

The normal SMS service is the ability to respond to SMS requests (SMS PULL) which is done with SMS-service configurations:

#---------------------------------------------
# SERVICES
#
# These are 'responses' to sms PULL messages, i.e. messages arriving from
# handsets. The response is based on message content. Only one sms-service is
# applied, using the first one to match.

group = sms-service
keyword = nop
text = "You asked nothing and I did it!"

# There should be always a 'default' service. This service is used when no
# other 'sms-service' is applied.

group = sms-service
keyword = default
text = "No service specified"

This is the most simple service just serving a static string (the value of text). The other and dynamic ways to respond to these requests I'll cover in another post.

Now I can start the SMSBox with /opt/kannel-1.4.3/sbin/smsbox -v 1 gw/smskannel.conf

2009-03-28 08:03:44 [4265] [0] INFO: Debug_lvl = 1, log_file = , log_lvl = 0
2009-03-28 08:03:44 [4265] [0] INFO: Service global sender set as '13013'
2009-03-28 08:03:44 [4265] [0] INFO: HTTP: Opening server at port 13013.
2009-03-28 08:03:44 [4265] [0] INFO: Set up send sms service at port 13013
2009-03-28 08:03:44 [4265] [0] INFO: Connected to bearerbox at 127.0.0.1 port 13001.

After starting these two services there are now a total of 4 open ports for fakesmsc, bearerbox and smsbox:

tcp        0      0 0.0.0.0:10000               0.0.0.0:*                   LISTEN
tcp        0      0 0.0.0.0:13000               0.0.0.0:*                   LISTEN
tcp        0      0 0.0.0.0:13001               0.0.0.0:*                   LISTEN
tcp        0      0 0.0.0.0:13013               0.0.0.0:*                   LISTEN

An example message flow

A simple demo can be run with the fakesmsc commandline tool like in ./test/fakesmsc -m 1 "12345678 87654321 text nop [the_parameters]":

2009-03-28 08:05:55 [4277] [0] INFO: Debug_lvl = -1, log_file = , log_lvl = 0
2009-03-28 08:05:55 [4277] [0] INFO: Host localhost Port 10000 interval 1.000 max-messages 1
2009-03-28 08:05:55 [4277] [0] INFO: fakesmsc starting
2009-03-28 08:05:55 [4277] [0] INFO: fakesmsc: sent message 1
2009-03-28 08:05:55 [4277] [0] INFO: Got message 1: <13013 12345678 text No service specified>

The Bearerbox logs:

2009-03-28 08:03:44 [4193] [5] INFO: Client connected from <127.0.0.1>
2009-03-28 08:05:55 [4193] [6] INFO: Fakesmsc client connected from 127.0.0.1

and the smsbox

2009-03-28 08:05:55 [4265] [4] INFO: Starting to service <nop [the_parameters]> from <12345678> to <87654321>

Summary

Using Kannel is still very easy to both compile, configure and run.

14 comments :

standard said...

I am working on Kannel here. Do you need to modify the modem.conf ? or the conf file is automatically updated once you insert the usb modem?

Sweetxml said...

Hi standard

I'm 100% sure I understand your question, but I didn't update the modems.conf file, I just included it. I did consider finding the part that I needed but couldn't figure it out and didn't want to do it by trial and error, so I just decided that I was happy with a working configuration. I don't expect the file to be updated since if that was happening I think I should be able to do without it in the first place.

Brgds Brian

mwagiru said...

bernard@morpheus:/etc/kannel$ sudo /usr/sbin/bearerbox -v 1 kannel.conf
...
2009-08-25 16:35:48 [2313] [0] WARNING: DLR: using default 'internal' for storage type.
2009-08-25 16:35:48 [2313] [0] INFO: DLR using storage type: internal
2009-08-25 16:35:48 [2313] [0] INFO: Added logfile `/var/log/kannel/bearerbox.log' with level `0'.
2009-08-25 16:35:48 [2313] [0] ERROR: No 'smsbox' group in configuration, but smsbox-port set
2009-08-25 16:35:48 [2313] [0] PANIC: Cannot start with corrupted configuration
2009-08-25 16:35:48 [2313] [0] PANIC: /usr/sbin/bearerbox(gw_panic+0xd4) [0x80d4674]
2009-08-25 16:35:48 [2313] [0] PANIC: /usr/sbin/bearerbox(main+0xeac) [0x80558fc]
2009-08-25 16:35:48 [2313] [0] PANIC: /lib/tls/i686/cmov/libc.so.6(__libc_start_main+0xe5) [0xb79b5775]
2009-08-25 16:35:48 [2313] [0] PANIC: /usr/sbin/bearerbox [0x8053f31]
bernard@morpheus:/etc/kannel$ sudo vim /etc/kannel/kannel.conf

Sweetxml said...

Hi mwagiru

Though you don't state any questions I guess that you want to know why it doesn't work for you.
First I'm no kannel-guru, but it seems very clear that you have a problem with your configuration file as it dumps the error message:

ERROR: No 'smsbox' group in configuration, but smsbox-port set

which leads to a

PANIC: Cannot start with corrupted configuration

I'll suggest that you either try out the default configuration, the documentation or the usermail list.

Best regards
Brian

Telmo Pimentel Mota said...

Hi,

I am having problems to use sms-service with get-url.
Can you provide a working sample?

Sweetxml said...

Hi Telmo Pimentel Mota

I don't have sample ready and it's been quite some time since I last looked into this - but what is your problem? and how does it show in your log? You could start with a really simple hardcoded service. Is there something in the usermanual[1] that you don't understand?

Brgds Brian
[1] http://www.kannel.org/download/1.5.0/userguide-1.5.0/userguide.html

Telmo Pimentel Mota said...

I am using an SMSC Simulator from opensmpp.logica.com. It is my only smsc configured.
Below is my only sms-service entry:

group = sms-service
keyword = default
get-url = http://localhost:8080/KannelCallBak/?sms=%a

I see Kannel logs showing that the sms was received and forwarded to my smsbox, but the get-url is not called. :(

Sweetxml said...

hmm. I'm pretty blank on this.
Does it respond if you fix it to:

text = "No action specified"

instead of using get-url?

Does you get-url work - that is if you call with the expected string?

Anonymous said...

Hi

Can't we use Wavecom Q2303A GSM Modem with Module USB AT Commands as a SMS Gateway for send/recive sms Using Kannel?

Sweetxml said...

Hi Anon

Honestly I don't know, think you'll need to find either a supplier or another forum to help you with that question.

Brgds Brian

tman said...

Hello,

thanks for a great tutorial. However, for me everything seems to go well until my config file is read for modems. I do not know why it reads modems. the gateway then goes into PANIC. May you please assist

# My own 'virtual' SMSC with the HUAWEI E169
group = smsc
smsc = at
modemtype = auto
device = "/dev/ttyUSB_utps_modem"
my-number = "26773334913"
log-level = 0
pin = "0000"



2012-01-30 11:42:34 [4846] [8] DEBUG: AT2[/dev/ttyUSB_utps_modem]: Reading modem definitions from
2012-01-30 11:42:34 [4846] [8] DEBUG: AT2[/dev/ttyUSB_utps_modem]: Found <1> modems in config
2012-01-30 11:42:34 [4846] [8] PANIC: AT2[/dev/ttyUSB_utps_modem]: Cannot detect modem and generic not found
2012-01-30 11:42:34 [4846] [8] PANIC: /usr/local/kannel/sbin/bearerbox(gw_panic+0xbc) [0x80d03bc]

tman said...

Hello,

Found the issue with my last post. The modem definition in the kannel configuration file "smskannel.conf" must have a modem id, name equal to what the AT2 driver "detect modem type" returns.

Now issue is getting the E173 CNIM values and actaully getting the program to receive an sms

Sweetxml said...

Hi tman

Glad to here that you've made progress. I really can't help you out, since I haven't used kannel since I wrote this blogpost. If you still think I can :-) post you're logs, since having a new pair of eyes might actually do a difference.

Brgds Brian

Anonymous said...

will fakesms work only afer connecting the modem?