Friday, December 29, 2006

Getting an Rconnect card working in linux

Well I thought this would be pretty difficult but turned out a lot simpler though.

First the specs
I am using a Dell D620 laptop with the Rconnect card in my PCMCI slot. I specifically told the Reliance guys to get me a card that works for Linux and they gave me a Huawei one . The normal ZTE cards they give don't work with linux AFAIK. Nevertheless the drivers you get with the Huawei card are still for Windoze. But don't worry, if you are using the latest kernel it will get detected automatically. For the record, mine is 2.6.9-42.13 thats RHEL 4.

Now su as root. open vi and create this small script file say rconnect in your directory.
[root@nmoidu ~]# cat rconnect
sudo modprobe usbserial vendor=0x12d1 product=0x1001
mknod /dev/ttyUSB0 c 188 0
mknod /dev/ttyUSB1 c 188 1

Then set permissions for this to be executable.

Now for the modem properties and details of the dialup parameters, configure this file as below :

[root@nmoidu sysconfig]# cat /etc/wvdial.conf
[Modem0]
Modem = /dev/ttyUSB0
Baud = 115200
SetVolume = 0
Dial Command = ATDT
Init1 = ATZ
Init3 = ATM0
FlowControl = NOFLOW
[Dialer Rconnect]
Username = 93293292323
Password = 932939392323
Phone = #777
Stupid Mode = 1
Init1 = ATZ
Init2 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
Inherits = Modem0
[root@nmoidu sysconfig]#

Then add this file to setup the network parameters of the Rconnect interface.
[root@nmoidu ~]# cat /etc/sysconfig/network-scripts/ifcfg-Rconnect
# Please read /usr/share/doc/initscripts-*/sysconfig.txt
# for the documentation of these parameters.
ONBOOT=no
USERCTL=yes
PEERDNS=yes
TYPE=Modem
DEVICE=ppp0
BOOTPROTO=dialup
AC=off
BSDCOMP=off
VJCCOMP=off
CCP=off
PC=off
VJ=off
LINESPEED=115200
MODEMPORT=/dev/ttyUSB0
PROVIDER=Rconnect
DEFROUTE=yes
PERSIST=no
PAPNAME=93293293293# Change this no...:)
WVDIALSECT=Rconnect
MODEMNAME=Modem0
DEMAND=no
IPV6INIT=no
IDLETIMEOUT=600
[root@nmoidu ~]#

Customize each script and file according to the specifics in your machine like the device name and your phone no. etc. Run a dmesg to see under what device name your card is detected .
Now Run the script rconnect twice. Then do an ifup Rconnect.
Btw you'll have to call up Reliance and ask them to activate the card first and then the first connection will have to be done from a Windoze machine using the Rconnect software. Thats the unavoidable world of Windows . You have to live with it ;) .
Now once you are connected, browse , enjoy........


Alternately you can do it using the GUI too.
Create the rconnect script, run it.
Then open system-config-network . Add a new modem connection. Set the provider name to Reliance. Give no. to be dialled as #777. Enter your mob. no and password . Leave the other parameters as it is.
Follow the wizard and create the the new connection. Activate the new device from the GUI. Thats it.

In case of issues, Pls let me know. Leave a comment or mail me.

Wednesday, December 06, 2006

Setting up an SMS gateway

I am writing this little howto for setting up an email2sms gateway which basically sends a mail to your mobile , like any alerts etc.

Hardware/software requirements are:

1) A GSM modem (or a phone which can act as one). The key point is it should be able to talk to Linux as a modem. A lot of the modern CDMA/GSM phones have modems that need proprietary drivers to access the modem. These generally are not available for Linux.Choose one with support for linux.
Put your SIM into the modem, connect the serial cable to a serial-to-USB converter and connect to the system via USB port.( Nowadays I've seen the modems coming directly with a USB interface).

2) Linux , we used FC 5 since the modem drivers had some issues on RHEL.

3) The SMS software. We use here smstools ( http://smstools.meinemullemaus.de/)

Download the tar.gz file and do the normal installation - unzip , make , make install.

Go to the configuration file /etc/smsd.conf . Configure as follows

[root@smsgw]# cat /etc/smsd.conf
# Example smsd.conf. Read the manual for a description

devices = GSM1 # Put in any name here for the modem to be identified.
logfile = /var/log/smsd.log # Set the log file here so that you can use it for debugging
loglevel = 7 # Check out the http://smstools.meinemullemaus.de/configure.html for details


outgoing = /var/spool/sms/outgoing # Define directory where the mails will come
checked = /var/spool/sms/checked
failed = /var/spool/sms/failed # Failed sms , for reasons like say - nil balance in SIM
incoming = /var/spool/sms/incoming # Define directory where incoming sms will be stored
sent = /var/spool/sms/sent # Mails sent out as sms

[GSM1] # Define each modem you named above , eg GSM1 , GSM2 etc.
device = /dev/ttyUSB0 # Define the device name of the modem
incoming = yes

We had used a serial-to-USB converter to connect the modem to the system. The modem hence appears to the system as a SUB device. So we define the GSM modem device as /dev/ttyUSB0. The mails that come into the outgoing folder should have the To field as the mobile no. of the person to whom the sms should be sent to. For automatically setting it to change the names of the mail id in the To field of the mail to the phone no. you will have to configure a filter like procmail to automatically change this.

[root@odin sent]# cat /etc/procmailrc
SHELL=/bin/sh
LOGFILE=/var/log/Proctest.log
LOG="--- Logging for ${LOGNAME}, "
#First, a few environment variables are included.
#Troubleshooting:
VERBOSE=yes
LOGABSTRACT=all

:0
* ^TO_ .*@company.com
| /usr/local/bin/extract-headers.sh

This calls for execution of the script extract-headers.sh for all mails coming to @ company.com domain.
The extract-headers.sh is just a script to extract the required headers only from the mail body and replace it with the phone no.s of the persons concerned in the To field , since the smsd sends the message to the number given in the To field of the message. See http://smstools.meinemullemaus.de/fileformat.html for more details on the sms format to be followed.

[root@smsgw]# cat /usr/local/bin/extract-headers.sh
#!/bin/bash
TMPFILE=$(mktemp)
FILE=$(mktemp -p /var/spool/sms/outgoing/)
formail -k -XFrom: -XSubject: -XTo: >> $TMPFILE # From, To and Subject headers copied to TMPFILE
rcptad=$(grep ^To: $TMPFILE | gawk '{print $2}') # search To field, output only mail-id part
perl -pi -e 's/To.*/To: 91999999999/' $TMPFILE;; # Replace mail id with mobile no.
FROM=$(grep From: $TMPFILE |gawk -F":" '{print $2}') # Get the From machine name
echo "from $FROM" >> $TMPFILE # Push the line "from sender-name" to the TMPFILE
cp $TMPFILE $FILE # Move the contents of TMPFILE to FILE
rm $TMPFILE # Delete TMPFILE



END of story. Start smsd in your system. put some mail in the /var/spool/outgoing folder , pay your mobile bill ;) and pray for the sms alerts to come :).
Contact me for any doubts.
___________________________________________________________________________

--
Thanks and Regards
Nabeel Moidu
Red Hat Inc.
Pune, India

If we don't believe in freedom of expression for people we despise, we don't believe in it at all. Noam Chomsky