Requirements
1. Hardware
-computer installed
with Centos (I used Centos 6.7)
-safaricom modem
with a valid sim card (I used huawei e303s-1)
2. Packages
- wvdial
- usb_modeswitch
These packages can
be installed using yum if they are not already in your Centos box:
yum
install wvdial
yum
install usb_modeswitch
Configuration
steps
1. Plug the usb
modem and check if it has been detected using the lsusb command.
[WM@Wallace ~]$ lsusb
Bus 002 Device 004: ID 12d1:14fe
Huawei Technologies Co., Ltd. Mass Storage Mode
The
mode of the dongle could be either Modem/Networkcard mode or Mass
storage mode, indicated at the end of the line as above. For the
dongle to work, it has to be in Modem mode.
From
the output of lsusb,
you need to note two codes, 12d1 and 14fe. 12d1
is known as vendor code while
14fe is the product code which indicates the mode the dongle is
currently operating in, in
this case Mass Storage Mode.
Note:
Depending on your USB dongle, these codes may vary. If they
don’t match mine, just make
sure to note what your codes are and replace mine with yours in this
process.
2.
If your dongle is not in modem mode,
change it by running the
following command in terminal
usb_modeswitch
-v 0x12d1 -p 0x1506 -H -W
3.
Now access the file
/etc/usb_modeswitch.conf using an editor. Make sure to have root
privileges as editing files in /etc/ require root permission.
[WM@Wallace ~]$ su
Password:
[root@Wallace WM]# vim
/etc/usb_modeswitch.conf
Add
the following content to
that file:
DefaultVendor= 0x12d1
DefaultProduct=0x14fe
TargetVendor= 0x12d1
TargetProductList="1001,1406,140b,140c,141b,14ac,1506"
CheckSuccess=20
MessageContent="55534243123456780000000000000011060000000000000000000000000000"
NB
Question:
Where do we get the content to add to /etc/usb_modeswitch.conf?
Answer:
DefaultVendor
and DefaultProduct are obtained from lsusb command when
running the command after connecting the dongle for the first time.
Note that in my case, these are the codes I obtained in step 1 above.
TargetVendor,
TargetProductList and Message
Content are obtained from
/etc/usb_modeswitch.d. Inside this directory are several custom files
of the form
DefaultVendor:DefaultProduct e.g 03f0:002a, 19d2:2000 etc.
Find the one whose name
matches your codes and get into it. The
TargetProductList can be replaced with TargetProduct=0x1506, where
1506 is the code of the dongle in Modem
Mode. If you use the
TargetProductList, make
sure one of the codes in the list is for your dongle in Modem mode.
However
for my computer there was no file 12d1:14fe as needed for my dongle,
so I took the content of my usb_modeswitch.conf file from Sachin
Sharma's blog and edited
it appropriately.
4. Now
open /etc/wvdial.conf in an editor, copy the following contents to it
and save.
[Dialer Defaults]
Init1 = ATZ
Init2 = ATQ0 V1 E1 S0=0 &C1
&D2
Init3 =
AT+CGDCONT=1,"IP","safaricom"
Password = data
Phone = *99#
Modem Type = Analog Modem
Stupid Mode = 1
Baud = 9600
New PPPD = yes
Modem = /dev/ttyUSB_utps_modem
ISDN = 0
Username = saf
Carrier Check = no
FlowControl = Hardware(CRTSCTS)
Init3 = AT+CPIN=xxxx
In
the last line of the above content, replace xxxx with the pin of your
safaricom sim card. If the sim card doesn’t have a pin, remove that
line from the file.
5.
Once you’ve done all these,
connect using wvdial command.
[root@Wallace WM]# wvdial
--> WvDial: Internet dialer
version 1.60
--> Cannot get information for
serial port.
--> Initializing modem.
--> Sending: ATZ
ATZ
OK
--> Sending: ATQ0 V1 E1 S0=0
&C1 &D2
ATQ0 V1 E1 S0=0 &C1 &D2
OK
--> Sending: AT+CPIN=5362
AT+CPIN=5362
OK
--> Modem initialized.
--> Sending: ATDT*99#
--> Waiting for carrier.
ATDT*99#
CONNECT
--> Carrier detected.
Starting PPP immediately.
--> Starting pppd at Thu Sep
7 10:08:43 2017
--> Pid of pppd: 31703
--> Using interface ppp0
--> pppd: 5
--> pppd: 5
--> pppd: 5
--> pppd: 5
--> pppd: 5
--> local IP address
105.160.80.173
--> pppd: 5
--> remote IP address
10.64.64.64
--> pppd: 5
--> primary DNS address
196.201.216.21
--> pppd: 5
--> secondary DNS address
196.201.217.7
--> pppd: 5
--> pppd: 5
Modem
connects now!
Scipt
to do this for you.
#!/bin/bash
sleep 2
cat /home/WM/pswd | sudo
usb_modeswitch -v 0x12d1 -p 0x1506 -H -W
sleep 2
cat /home/WM/pswd | sudo
wvdialconf
wvdial
Troubleshoot
Issue
1: Device or resource busy.
Ensure
you run dongle as root.
Issue
2: +CME ERROR 11. Sim PIN required.
Occurs
when you try to access sim card that has a pin without providing the
pin. Refer to the Step 4 in this article to see the line you ought to
add to your /etc/wvdial.conf file.
Issue
3: +CME ERROR 3. Operation not allowed.
I
haven’t quite figured out what causes this error. But what I
realized was that, every time you run wvdial the wvdial.conf file is
edited. The following line is removed
Init3
= AT+CGDCONT=1,"IP","safaricom"
Perhaps
its got something to do with this error. Don’t know though! But
thought I should mention it!
Also,
make sure your sim card is inserted properly.
These micro sim cards are hard to align with the big slots of modems
sometimes.
Issue
4: +CME ERROR number, where number is an integer between 0 – 772.
Refer to this link
obtained from Micromedia
about CME
errors and their description.
References
2.
sachinsharm.wordpress.com/2013/08/11/installing-and-configuring-usb-3g-datacard-on-centosrhel-6-3/
3.
https://bbs.archlinux.org/viewtopic.php?id=171617
4.
https://www.thefanclub.co.za/how-to/how-setup-usb-3g-modem-raspberry-pi-using-usbmodeswitch-and-wvdial
5.
http://blog.magiksys.net/linux-umts-modem-wvdial-usb_modeswitch-mobistar
7.
man pages for wvdial and usb_modeswitch