SummerTraining09:Projects/Kannel SMS setup on fedora
From Dgplug
| Task: | Kannel SMS setup on Fedora |
| Mentor: | mbuf |
| Participants: | zer0c00l |
Contents |
Overview
Kannel is an open source WAP/SMS gateway used for sending and receiving text messages.
Usage Patterns
The usage pattern was always:
- User sends us a message.
- We might send them a reply after processing it.
- We might also periodically need to be able to send the user a message.
Things Needed
The following software environment and gadgets are needed to continue with the setup:
- Fedora 10
- Internet connectivity to install kannel (Optional if kannel was already installed or compiled offline)
- A WAP enabled mobile phone with SIM (GSM) (i have used Nokia 3110c)
- A usb connector which could be used to connect the mobile phone to your computer.(I haven't tested with bluetooth)
- Patience
Installing Kannel on Fedora
Kannel is available in official Fedora repository.
yum install kannel
optional packages
wvdial
yum install wvdial
Configuring Kannel as SMS Gateway
Kannel stores its configuration file in /etc/kannel.conf
The configuration file can be divided into three parts:
- bearerbox configurations,
- smsbox configurations,
- wapbox configurations.
The WAPBOX configurations are not concentrated in this document.
To setup SMS Gateway with mobile phone as SMSCenter:
- The bearerbox configuration MUST include smsbox-port variable with valid port.
- The SMSC group MUST be defined in the configuration file to use a modem.
- The modem group MUST be defined in the configuration file.
- The smsbox group MUST be define in the configuration file.
- One or more send-sms groups MUST be defined in the configuration file.
- One or more SMS-Service groups shall be defined to process incoming SMS in the configuration file.(Note:Only needed if you want to process incoming text messages and send appropriate)
Bearerbox configuration
The Configuration for Kannel MUST include a group for bearerbox configuration named as ’core’.
Sample bearer box configuration:
# Default kannel configuration file #core group 'mandatory' identifies the group group = core #port for http administration admin-port = 13000 #Password for http administration admin-password = hard2guess #Password to check status of kannel status-password = statuspass #Allow only localhost for now admin-deny-ip = "*.*.*.*" admin-allow-ip = "127.0.0.1" #For SMS gateway smsbox-port = 13001 #For WAP gateway commented because we don't need this for now #wapbox-port = 13002 #Allow localhost only box-deny-ip = "*.*.*.*" box-allow-ip = "127.0.0.1" wdp-interface-name = "*" #Log filename and log-level log-file = "/var/log/kannel/bearerbox.log" log-level = 1
Note: The log level can be 0-4 , use 0 or 1 when you are in testing and debugging phase or disk space is cheap.
SMS Center
To set up the SMS center at Kannel, you have to add a ’smsc’ group in the configuration file.Each group must me separated by a line.
The mobile phone is used as SMS center.Connect your wap enabled mobile to your computer in "Nokia mode" (Or what ever mode that makes your mobile phone as an usb modem)
Open up terminal and type the following command:
/bin/dmesg/ | tail -20
The output will be similar to,
[..] usb 5-2: new full speed USB device using uhci_hcd and address 2 usb 5-2: configuration #1 chosen from 1 choice usb 5-2: New USB device found, idVendor=0421, idProduct=005e usb 5-2: New USB device strings: Mfr=1, Product=2, SerialNumber=0 usb 5-2: Product: Nokia 3110c usb 5-2: Manufacturer: Nokia cdc_acm 5-2:1.1: ttyACM0: USB ACM device usbcore: registered new interface driver cdc_acm [..]
From the output it's obvious that mobile phone was detected,
cdc_acm 5-2:1.1: ttyACM0: USB ACM device
So the usb modem is,
/dev/ttyACM0
sample SMS Center group configuration:
#Identifies the SMS Center group group = smsc #Tells kannel that we are going to use mobile as smsc smsc = at #Sets the modem type to auto modemtype = auto #Identifies the modem device = /dev/ttyACM0 #It should be your mobile number my-number = 9999999999 log-level = 1
Modem Configuration
The modem configuration is one of the important part,the init-strings are used to initialize the modem and can vary from vendor to vendor.
Sample Modem configuration:
#It should be changed to work for your mobile group = modems id = nokia name = "Nokia 3110c" detect-string = "Nokia" init-string = "ATZ" init-string = "AT Q0 V1 E1 S0=0 &C1 &D2 +FCLASS=0"
Method to find out the init-string
- Make sure that you have installed wvdial (yum install wvdial)
- Make sure that you have connected you mobile phone and it got detected
- Run the following command as root
wvdialconf
- The possible init-string for modem configuration can be found in file
/etc/wvdial.conf
Sample wvdialconf file
-bash-3.2# cat /etc/wvdial.conf [Dialer Defaults] Init2 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0 Modem Type = USB Modem ; Phone = <Target Phone Number> ISDN = 0 ; Username = <Your Login Name> Init1 = ATZ ; Password = <Your Password> Modem = /dev/ttyACM0 Baud = 460800
Init1 and Init2 of wvdialconf file can be used as init-strings in kannel.conf.
If you have no luck with wvdial, then try the following:
- GSM AT commands follow 3GPP specifications, so read 3GPP specifications.
- Consult your manufacturer for support
- Ask in kannel users mailing list
- Google is your friend.
A brief note on Nokia Mobile phones
A lot of Nokia models do not support AT+CNMI command, which kannel uses as default to configure your modem.So you MUST supply an alternative init-string in group modems that works with your Nokia phone model.
SMSBOX configuration
group = smsbox bearerbox-host = 127.0.0.1 sendsms-port = 13013 #The sender number to be used in text messages global-sender = "+919994989838" log-level = 0
SEND-SMS Group configuration
group = sendsms-user #Username and Password for sending sms using HTTP interface username = kannel password = hard2guess concatenation = true #can send a longer text message about 3 smses ( 3*160) max-messages = 3
Running Kannel
First start the Bearerbox using below command
bearerbox -v 1 /etc/kannel.conf &
-bash-3.2# bearerbox -v 1 /etc/kannel.conf & [1] 24377 -bash-3.2# 2009-07-01 18:24:32 [24377] [0] INFO: Debug_lvl = 1, log_file = <none>, log_lvl = 0 2009-07-01 18:24:32 [24377] [0] WARNING: DLR: using default 'internal' for storage type. 2009-07-01 18:24:32 [24377] [0] INFO: DLR using storage type: internal 2009-07-01 18:24:32 [24377] [0] INFO: Added logfile `/var/log/kannel /bearerbox.log' with level `1'. 2009-07-01 18:24:32 [24377] [0] INFO: HTTP: Opening server at port 13000. 2009-07-01 18:24:32 [24377] [0] INFO: BOXC: 'smsbox-max-pending' not set, using default (100). 2009-07-01 18:24:32 [24377] [0] INFO: Set SMS resend frequency to 60 seconds. 2009-07-01 18:24:32 [24377] [0] INFO: SMS resend retry set to unlimited. 2009-07-01 18:24:32 [24377] [0] INFO: DLR rerouting for smsc id <(null)> disabled. 2009-07-01 18:24:32 [24377] [0] INFO: AT2[/dev/ttyACM0]: configuration doesn't show modemtype. will autodetect 2009-07-01 18:24:32 [24377] [6] INFO: AT2[/dev/ttyACM0]: opening device 2009-07-01 18:24:32 [24377] [0] INFO: Adding interface * 2009-07-01 18:24:32 [24377] [0] ERROR: Missing wapbox-port variable, cannot start WAP 2009-07-01 18:24:32 [24377] [0] INFO: ---------------------------------------- 2009-07-01 18:24:32 [24377] [0] INFO: Kannel bearerbox II version 1.4.1 starting 2009-07-01 18:24:32 [24377] [0] INFO: MAIN: Start-up done, entering mainloop 2009-07-01 18:24:33 [24377] [6] INFO: AT2[/dev/ttyACM0]: speed set to 115200 2009-07-01 18:24:35 [24377] [6] INFO: AT2[/dev/ttyACM0]: closing device 2009-07-01 18:24:35 [24377] [6] INFO: AT2[/dev/ttyACM0]: detect speed is 115200 2009-07-01 18:24:35 [24377] [6] INFO: AT2[/dev/ttyACM0]: opening device 2009-07-01 18:24:36 [24377] [6] INFO: AT2[/dev/ttyACM0]: speed set to 115200 2009-07-01 18:24:38 [24377] [6] INFO: AT2[/dev/ttyACM0]: closing device 2009-07-01 18:24:38 [24377] [6] INFO: AT2[/dev/ttyACM0]: opening device 2009-07-01 18:24:38 [24377] [6] INFO: AT2[/dev/ttyACM0]: init device 2009-07-01 18:24:38 [24377] [6] INFO: AT2[/dev/ttyACM0]: speed set to 115200 2009-07-01 18:24:39 [24377] [6] INFO: AT2[/dev/ttyACM0]: AT SMSC successfully opened.
Then, run Smsbox using below command
smsbox -v 1 /etc/kannel.conf &
-bash-3.2# smsbox -v 1 /etc/kannel.conf & [2] 24658 -bash-3.2# 2009-07-01 18:29:50 [24658] [0] INFO: Debug_lvl = 1, log_file = <none>, log_lvl = 0 2009-07-01 18:29:50 [24658] [0] INFO: Service global sender set as '+919994989890' 2009-07-01 18:29:50 [24658] [0] INFO: HTTP: Opening server at port 13013. 2009-07-01 18:29:50 [24658] [0] INFO: Set up send sms service at port 13013 2009-07-01 18:29:50 [24377] [5] INFO: Client connected from <127.0.0.1> 2009-07-01 18:29:50 [24658] [0] INFO: Connected to bearerbox at 127.0.0.1 port 13001.
Sending SMS
Text messages can be sent using http interface.For example.
http://127.0.0.1:13013/cgi-bin/sendsms?username=kannel&password=hard2guess&to=9486987049&text=This+msg+is+sent+from+saga%27s+computer+with+kannel+please+reply+back+if+u+received+it
Replace the port, username,password,to and text with your own values to send text messages.
Administration using web interface
To check kannel status
http://127.0.0.1:13000/status?password=hard2guess
Kannel bearerbox version `1.4.1'. Build `Feb 21 2008 11:10:28', compiler `4.3.0 20080218 (Red Hat 4.3.0-0.10)'. System Linux, release 2.6.27.25-170.2.72.fc10.i686, version #1 SMP Sun Jun 21 19:03:24 EDT 2009, machine i686. Hostname localhost, IP 127.0.0.1. Libxml version 2.6.31. Using OpenSSL 0.9.8g 19 Oct 2007. Using native malloc.
Status: running, uptime 0d 0h 7m 50s
WDP: received 0 (0 queued), sent 0 (0 queued)
SMS: received 0 (0 queued), sent 0 (0 queued), store size -1
SMS: inbound 0.00 msg/sec, outbound 0.00 msg/sec
DLR: 0 queued, using internal storage
Box connections:
smsbox:(none), IP 127.0.0.1 (0 queued), (on-line 0d 0h 2m 32s)
SMSC connections:
unknown AT2[/dev/ttyACM0] (online 463s, rcvd 0, sent 0, failed 0, queued 0 msgs
http://127.0.0.1:13000/ Possible commands are: status store-status log-level shutdown suspend isolate resume restart flush-dlr stop-smsc start-smsc
Troubleshooting
Symptom:
bash-3.2$ bearerbox -v 1 /etc/kannel.conf [..] 2009-07-03 17:51:47 [8097] [6] INFO: AT2[/dev/ttyACM0]: opening device 2009-07-03 17:51:47 [8097] [6] ERROR: AT2[/dev/ttyACM0]: open failed! ERRNO=13 2009-07-03 17:51:47 [8097] [6] ERROR: System error 13: Permission denied 2009-07-03 17:51:47 [8097] [6] INFO: AT2[/dev/ttyACM0]: opening device 2009-07-03 17:51:47 [8097] [6] ERROR: AT2[/dev/ttyACM0]: open failed! ERRNO=13 [..]
Fix: Bearerbox and Smsbox should be invoked as a super user
bash-3.2$ sudo bearerbox -v 1 /etc/kannel.conf
Symptom:
-bash-3.2# bearerbox -v 1 /etc/kannel.conf [..] 2009-07-03 18:08:51 [9040] [0] INFO: AT2[/dev/ttyACM0]: configuration doesn't show modemtype. will autodetect 2009-07-03 18:08:51 [9040] [6] INFO: AT2[/dev/ttyACM0]: opening device 2009-07-03 18:08:51 [9040] [0] INFO: Adding interface * 2009-07-03 18:08:51 [9040] [0] ERROR: Missing wapbox-port variable, cannot start WAP 2009-07-03 18:08:51 [9040] [0] INFO: ---------------------------------------- 2009-07-03 18:08:51 [9040] [0] INFO: Kannel bearerbox II version 1.4.1 starting 2009-07-03 18:08:51 [9040] [0] INFO: MAIN: Start-up done, entering mainloop 2009-07-03 18:08:52 [9040] [6] INFO: AT2[/dev/ttyACM0]: speed set to 115200 2009-07-03 18:08:54 [9040] [6] INFO: AT2[/dev/ttyACM0]: closing device 2009-07-03 18:08:54 [9040] [6] INFO: AT2[/dev/ttyACM0]: detect speed is 115200 2009-07-03 18:08:54 [9040] [6] INFO: AT2[/dev/ttyACM0]: opening device 2009-07-03 18:08:55 [9040] [6] INFO: AT2[/dev/ttyACM0]: speed set to 115200 2009-07-03 18:08:57 [9040] [6] INFO: AT2[/dev/ttyACM0]: closing device 2009-07-03 18:08:57 [9040] [6] INFO: AT2[/dev/ttyACM0]: opening device 2009-07-03 18:08:57 [9040] [6] INFO: AT2[/dev/ttyACM0]: init device 2009-07-03 18:08:57 [9040] [6] INFO: AT2[/dev/ttyACM0]: speed set to 115200 2009-07-03 18:08:58 [9040] [6] ERROR: AT2[/dev/ttyACM0]: Generic error: ERROR 2009-07-03 18:08:58 [9040] [6] ERROR: AT2[/dev/ttyACM0]: Opening failed. Terminating 2009-07-03 18:08:58 [9040] [6] INFO: AT2[/dev/ttyACM0]: closing device 2009-07-03 18:08:58 [9040] [6] INFO: AT2[/dev/ttyACM0]: opening device 2009-07-03 18:08:58 [9040] [6] INFO: AT2[/dev/ttyACM0]: init device 2009-07-03 18:08:58 [9040] [6] INFO: AT2[/dev/ttyACM0]: speed set to 115200 2009-07-03 18:08:59 [9040] [6] ERROR: AT2[/dev/ttyACM0]: Generic error: ERROR 2009-07-03 18:08:59 [9040] [6] ERROR: AT2[/dev/ttyACM0]: Opening failed. Terminating
Note:
2009-07-03 18:08:58 [9040] [6] ERROR: AT2[/dev/ttyACM0]: Generic error: ERROR
More Detailed log with log level 0:
[..] 2009-07-03 18:10:34 [9146] [0] INFO: Kannel bearerbox II version 1.4.1 starting 2009-07-03 18:10:34 [9146] [0] INFO: MAIN: Start-up done, entering mainloop 2009-07-03 18:10:34 [9146] [0] DEBUG: AT2[/dev/ttyACM0]: start called 2009-07-03 18:10:34 [9146] [7] DEBUG: sms_router: gwlist_len = 0 2009-07-03 18:10:35 [9146] [6] DEBUG: AT2[/dev/ttyACM0]: device opened 2009-07-03 18:10:35 [9146] [6] INFO: AT2[/dev/ttyACM0]: speed set to 115200 2009-07-03 18:10:35 [9146] [6] DEBUG: AT2[/dev/ttyACM0]: --> ^M 2009-07-03 18:10:37 [9146] [6] DEBUG: AT2[/dev/ttyACM0]: --> AT^M 2009-07-03 18:10:37 [9146] [6] DEBUG: AT2[/dev/ttyACM0]: <-- OK 2009-07-03 18:10:37 [9146] [6] INFO: AT2[/dev/ttyACM0]: closing device 2009-07-03 18:10:37 [9146] [6] INFO: AT2[/dev/ttyACM0]: detect speed is 115200 2009-07-03 18:10:37 [9146] [6] DEBUG: AT2[/dev/ttyACM0]: detecting modem type 2009-07-03 18:10:37 [9146] [6] INFO: AT2[/dev/ttyACM0]: opening device 2009-07-03 18:10:37 [9146] [6] DEBUG: AT2[/dev/ttyACM0]: device opened 2009-07-03 18:10:38 [9146] [6] DEBUG: AT2[/dev/ttyACM0]: device opened 2009-07-03 18:10:38 [9146] [6] INFO: AT2[/dev/ttyACM0]: speed set to 115200 2009-07-03 18:10:38 [9146] [6] DEBUG: AT2[/dev/ttyACM0]: --> ^M 2009-07-03 18:10:40 [9146] [6] DEBUG: AT2[/dev/ttyACM0]: --> AT^M 2009-07-03 18:10:40 [9146] [6] DEBUG: AT2[/dev/ttyACM0]: <-- OK 2009-07-03 18:10:40 [9146] [6] DEBUG: AT2[/dev/ttyACM0]: --> AT&F^M 2009-07-03 18:10:40 [9146] [6] DEBUG: AT2[/dev/ttyACM0]: <-- OK 2009-07-03 18:10:40 [9146] [6] DEBUG: AT2[/dev/ttyACM0]: --> ATE0^M 2009-07-03 18:10:40 [9146] [6] DEBUG: AT2[/dev/ttyACM0]: <-- ATE0 2009-07-03 18:10:40 [9146] [6] DEBUG: AT2[/dev/ttyACM0]: <-- OK 2009-07-03 18:10:40 [9146] [6] DEBUG: AT2[/dev/ttyACM0]: --> ATI^M 2009-07-03 18:10:40 [9146] [6] DEBUG: AT2[/dev/ttyACM0]: <-- Nokia 2009-07-03 18:10:40 [9146] [6] DEBUG: AT2[/dev/ttyACM0]: <-- OK 2009-07-03 18:10:40 [9146] [6] DEBUG: AT2[/dev/ttyACM0]: found string <Nokia>, using modem definition <Nokia 3110c> 2009-07-03 18:10:40 [9146] [6] DEBUG: AT2[/dev/ttyACM0]: --> AT+CSMS=?^M 2009-07-03 18:10:40 [9146] [6] DEBUG: AT2[/dev/ttyACM0]: <-- +CSMS: (0) 2009-07-03 18:10:40 [9146] [6] DEBUG: AT2[/dev/ttyACM0]: <-- OK 2009-07-03 18:10:40 [9146] [6] INFO: AT2[/dev/ttyACM0]: closing device 2009-07-03 18:10:40 [9146] [6] INFO: AT2[/dev/ttyACM0]: opening device 2009-07-03 18:10:40 [9146] [6] DEBUG: AT2[/dev/ttyACM0]: device opened 2009-07-03 18:10:40 [9146] [6] DEBUG: AT2[/dev/ttyACM0]: device opened 2009-07-03 18:10:40 [9146] [6] INFO: AT2[/dev/ttyACM0]: init device 2009-07-03 18:10:40 [9146] [6] INFO: AT2[/dev/ttyACM0]: speed set to 115200 2009-07-03 18:10:40 [9146] [6] DEBUG: AT2[/dev/ttyACM0]: --> ATZ^M 2009-07-03 18:10:40 [9146] [6] DEBUG: AT2[/dev/ttyACM0]: <-- OK 2009-07-03 18:10:40 [9146] [6] DEBUG: AT2[/dev/ttyACM0]: --> AT^M 2009-07-03 18:10:40 [9146] [6] DEBUG: AT2[/dev/ttyACM0]: <-- AT 2009-07-03 18:10:40 [9146] [6] DEBUG: AT2[/dev/ttyACM0]: <-- OK 2009-07-03 18:10:40 [9146] [6] DEBUG: AT2[/dev/ttyACM0]: --> AT&F^M 2009-07-03 18:10:40 [9146] [6] DEBUG: AT2[/dev/ttyACM0]: <-- AT&F 2009-07-03 18:10:40 [9146] [6] DEBUG: AT2[/dev/ttyACM0]: <-- OK 2009-07-03 18:10:40 [9146] [6] DEBUG: AT2[/dev/ttyACM0]: --> ATE0^M 2009-07-03 18:10:41 [9146] [6] DEBUG: AT2[/dev/ttyACM0]: <-- ATE0 2009-07-03 18:10:41 [9146] [6] DEBUG: AT2[/dev/ttyACM0]: <-- OK 2009-07-03 18:10:41 [9146] [6] DEBUG: AT2[/dev/ttyACM0]: --> AT+IFC=2,2^M 2009-07-03 18:10:41 [9146] [6] DEBUG: AT2[/dev/ttyACM0]: <-- OK 2009-07-03 18:10:41 [9146] [6] DEBUG: AT2[/dev/ttyACM0]: --> AT+CPIN?^M 2009-07-03 18:10:41 [9146] [6] DEBUG: AT2[/dev/ttyACM0]: <-- +CPIN: READY 2009-07-03 18:10:41 [9146] [6] DEBUG: AT2[/dev/ttyACM0]: <-- OK 2009-07-03 18:10:41 [9146] [6] DEBUG: AT2[/dev/ttyACM0]: --> AT+CMGF=0^M 2009-07-03 18:10:41 [9146] [6] DEBUG: AT2[/dev/ttyACM0]: <-- OK 2009-07-03 18:10:41 [9146] [6] DEBUG: AT2[/dev/ttyACM0]: --> AT+CSMS=?^M 2009-07-03 18:10:41 [9146] [6] DEBUG: AT2[/dev/ttyACM0]: <-- +CSMS: (0) 2009-07-03 18:10:41 [9146] [6] DEBUG: AT2[/dev/ttyACM0]: <-- OK 2009-07-03 18:10:41 [9146] [6] DEBUG: AT2[/dev/ttyACM0]: --> AT+CNMI=1,2,0,1,0^M 2009-07-03 18:10:41 [9146] [6] DEBUG: AT2[/dev/ttyACM0]: <-- ERROR 2009-07-03 18:10:41 [9146] [6] ERROR: AT2[/dev/ttyACM0]: Generic error: ERROR 2009-07-03 18:10:41 [9146] [6] ERROR: AT2[/dev/ttyACM0]: Opening failed. Terminating 2009-07-03 18:10:41 [9146] [6] INFO: AT2[/dev/ttyACM0]: closing device 2009-07-03 18:10:41 [9146] [6] INFO: AT2[/dev/ttyACM0]: opening device 2009-07-03 18:10:41 [9146] [6] DEBUG: AT2[/dev/ttyACM0]: device opened [..]
Closely looking at the log:
2009-07-03 18:10:41 [9146] [6] DEBUG: AT2[/dev/ttyACM0]: --> AT+CNMI=1,2,0,1,0^M 2009-07-03 18:10:41 [9146] [6] DEBUG: AT2[/dev/ttyACM0]: <-- ERROR 2009-07-03 18:10:41 [9146] [6] ERROR: AT2[/dev/ttyACM0]: Generic error: ERROR
So,AT+CNMI=1,2,0,1,0^M is not supported by your mobile phone (most nokia phones don't)
Fix: Init-string variable should be added to modem definitions group in order to make things work.
Complete configuration file
Copy of /etc/kannel.conf:
# Default kannel configuration file #core group 'mandatory' group = core #port for http administration admin-port = 13000 admin-password = hard2guess status-password = hard2guess admin-deny-ip = "*.*.*.*" admin-allow-ip = "127.0.0.1" #For SMS gateway smsbox-port = 13001 #wapbox-port = 13002 box-deny-ip = "*.*.*.*" box-allow-ip = "127.0.0.1" wdp-interface-name = "*" log-file = "/var/log/kannel/bearerbox.log" log-level = 1 #Access log #access-log = "/var/log/kannel/access.log"
group = smsc smsc = at modemtype = auto device = /dev/ttyACM0 my-number = "+919994989838" #speed = 460800 #pin = 1234 #sim-buffering = true log-level = 0
# MODEM DEFINITIONS group = modems id = nokia name = "Nokia 3110c" detect-string = "Nokia" init-string = "ATZ" init-string = "AT Q0 V1 E1 S0=0 &C1 &D2 +FCLASS=0" #message-storage = "EM"
group = smsbox bearerbox-host = 127.0.0.1 #we use sendsms-port for sending sms (http) sendsms-port = 13013 global-sender = "+919994989838" log-file = /var/log/kannel/smsbox.log log-level = 0
group = sendsms-user username = kannel password = hard2guess concatenation = true max-messages = 10