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.