加载中…
正文 字体大小:

how to configure Huawei E171 BSNL 3G USB modem on NetBSD

(2013-03-14 17:02:31)
标签:

huawei

netbsd

modem

e171

usb

With long spells of power outages in Bangalore the city i live in, a 3G USB modem supplied by BSNL at INR 1,800 (acquisition price) with a pre-paid facility makes for an attractive deal.

i've been a user of the Huawei E171 3G USB modem on Gentoo Linux. The two handy tools available are 'usb_modeswitch' and 'wvdial'. i'd say that 'usb_modeswitch' makes it easy to setup USB modem's that show up as usb storage devices.

Since i moved to NetBSD-current on my new AMD64 ASUS laptop, i intend to use the same modem. Btw, i like ASUS products very much. They are reliable and cost effective.

My first post on NetBSD current-users list was to ask for what is the 'usb_modeswitch' equivalent for NetBSD ?
http://mail-index.netbsd.org/current-users/2013/03/07/msg022201.html

i did share the vendorId and productId and other relevant info with the hope that some of the experienced folks will be able to help me out.

One of the community members Magnus Eriksson replied 'u3g/u3ginit' is supposed to do all that 'automagically'. http://mail-index.netbsd.org/current-users/2013/03/08/msg022204.html
Magnus has been trying to get his Huawei E353 modem.

Nonaka Kimihiro san replied to my mail with a patch and a suggestion to test and let him know of the outcome. http://mail-index.netbsd.org/current-users/2013/03/07/msg022200.html

i was very happy with his response and set about to download the NetBSD kernel source code and build a custom kernel. i'll write the details of how to build a custom kernel in a separate blog post.

NetBSD 6.99.17 (MYKERNEL) #0: Fri Mar  8 04:42:11 IST 2013
    root@x53u:/usr/src/sys/arch/amd64/compile/MYKERNEL

Subsequently, after compiling the custom kernel with the patches supplied by Kimihiro san, i tried attaching the Huawei E171 3g USB modem.

The red blinking led changed to blue blinking LED color. A quick scan at the console showed that the device was detected and 'ucom0' was assigned. Blue LED indicates a UMTS device and not a GPRS device.

Please see the log below for attach/detach scenario of the device.

ATTACH
--------
ehci1: handing over full speed device on port 1 to ohci1
u3ginit0 at uhub3 port 1: Switching to 3G mode
u3ginit0: detached
u3ginit0: at uhub3 port 1 (addr 2) disconnected
u3g0 at uhub3 port 1 configuration 1 interface 0
ucom0 at u3g0 portno 0: 3G Modem
u3g1 at uhub3 port 1 configuration 1 interface 1
u3g1: Missing bulk in/out for interface 1
u3g2 at uhub3 port 1 configuration 1 interface 2
ucom1 at u3g2 portno 0: 3G Modem
u3g3 at uhub3 port 1 configuration 1 interface 3
ucom2 at u3g3 portno 0: 3G Modem
umass1 at uhub3 port 1 configuration 1 interface 4
umass1: HUAWEI HUAWEI Mobile, rev 2.00/1.02, addr 2
umass1: using SCSI over Bulk-Only
scsibus1 at umass1: 2 targets, 1 lun per target
umass2 at uhub3 port 1 configuration 1 interface 5
cd1 at scsibus1 target 0 lun 0: <HUAWEI, Mass Storage, 2.31> cdrom removable
umass2: HUAWEI HUAWEI Mobile, rev 2.00/1.02, addr 2
umass2: using SCSI over Bulk-Only
scsibus2 at umass2: 2 targets, 1 lun per target
sd1 at scsibus2 target 0 lun 0: <HUAWEI, SD Storage, 2.31> disk removable
sd1: drive offline
sd1: unable to open device, error = 19

DETACH
--------
ucom0: detached
u3g0: detached
u3g0: at uhub3 port 1 (addr 2) disconnected
u3g1: detached
u3g1: at uhub3 port 1 (addr 2) disconnected
ucom1: detached
u3g2: detached
u3g2: at uhub3 port 1 (addr 2) disconnected
ucom2: detached
u3g3: detached
u3g3: at uhub3 port 1 (addr 2) disconnected
cd1: detached
scsibus1: detached
umass1: detached
umass1: at uhub3 port 1 (addr 2) disconnected
sd1: detached
scsibus2: detached
umass2: detached
umass2: at uhub3 port 1 (addr 2) disconnected

This was a very positive sign and i needed to check if the device acccepts the various AT modem commands. The book 'C programmer's guide to Serial communications' by Joe Campbell was helpful.

# tip ucom0

AT
ATZ
ATI
AT&CSQ
AT&V

Unfortunately, the last command resulted in ERROR. i donot know the reason. Btw, to exit a 'tip' session use (~.)

The next step was to learn to use the 'pppd' daemon and the chat script files. i used to write these scripts 5-6 years ago, but since then i hadn't used them and did not have a backup.

Anyway i set about learning them from the NetBSD documentation and old pages still available on the internet.

I created an 'pppd' options file, named 'bsnl3g' in '/etc/ppp/peers/' directory

noauth
connect "/usr/pkg/sbin/chat -v -f /etc/ppp/peers/bsnl3g.chat"
/dev/ttyU0
460800
local
defaultroute
noipdefault
usepeerdns
novj
persist
user ' '
password ' '
debug
logfile "ppp.log"

and then a chat script file, named 'bsnl3g.chat' in '/etc/ppp/peers/' directory.

ECHO ON
ABORT 'NO CARRIER'
ABORT 'NO DIALTONE'
ABORT 'NO ANSWER'
ABORT 'DELAYED'
ABORT 'ERROR'
ABORT 'BUSY'
'' '\rAT'
'' ATZ
OK 'AT+CGDCONT=1,"IP","bsnlnet"'
OK 'ATDT*99#'
TIMEOUT 30
CONNECT ''
HANGUP ON

The entries in both the files were evolved by trial and error. i must highlight the 'man'ual pages for both 'pppd' and 'chat' are very well written. it took me sometime, but i could refer and recheck my own assumptions and the options used.

The 'pppd' daemon was excuted with the following command

# pppd call bsnl3g

Bingo, the red blinking LED turned to blue stable LED. That was real awesome experience.

A quick check at the ppp.log  showed the following lines:


OK

OK

CONNECT
Serial connection established.
Using interface ppp0
Connect: ppp0 <--> /dev/ttyU0
sent [LCP ConfReq id=0x1 <asyncmap 0x0> <magic 0x99fe808a> <pcomp> <accomp>]
rcvd [LCP ConfReq id=0x1 <accomp> <pcomp> <asyncmap 0x0> <mru 1500> <magic 0x543> <auth chap MD5>]
sent [LCP ConfAck id=0x1 <accomp> <pcomp> <asyncmap 0x0> <mru 1500> <magic 0x543> <auth chap MD5>]
rcvd [LCP ConfAck id=0x1 <asyncmap 0x0> <magic 0x99fe808a> <pcomp> <accomp>]
rcvd [CHAP Challenge id=0x1 <bddfeb891ef1b48cdb1654d02f7bd8a4>, name = "HUAWEI_CHAP_SRVR"]
sent [CHAP Response id=0x1 <2b8cfd34446ec08d458bc0cd6e6ff2bd>, name = " "]
rcvd [CHAP Success id=0x1 "Welcome!!"]
CHAP authentication succeeded: Welcome!!
CHAP authentication succeeded
sent [CCP ConfReq id=0x1 <deflate 15> <deflate(old#) 15> <bsd v1 15>]
sent [IPCP ConfReq id=0x1 <addr 0.0.0.0> <ms-dns1 0.0.0.0> <ms-dns2 0.0.0.0>]
rcvd [IPCP ConfReq id=0x1]
sent [IPCP ConfNak id=0x1 <addr 0.0.0.0>]
rcvd [LCP ProtRej id=0x2 80 fd 01 01 00 0f 1a 04 78 00 18 04 78 00 15 03 2f]
Protocol-Reject for 'Compression Control Protocol' (0x80fd) received
rcvd [IPCP ConfNak id=0x1 <ms-dns1 0.0.0.0> <ms-dns2 0.0.0.0>]
sent [IPCP ConfReq id=0x2 <addr 0.0.0.0> <ms-dns1 0.0.0.0> <ms-dns2 0.0.0.0>]
rcvd [IPCP ConfReq id=0x2]
sent [IPCP ConfAck id=0x2]
rcvd [IPCP ConfNak id=0x2 <ms-dns1 0.0.0.0> <ms-dns2 0.0.0.0>]
sent [IPCP ConfReq id=0x3 <addr 0.0.0.0> <ms-dns1 0.0.0.0> <ms-dns2 0.0.0.0>]
rcvd [IPCP ConfNak id=0x3 <ms-dns1 0.0.0.0> <ms-dns2 0.0.0.0>]
sent [IPCP ConfReq id=0x4 <addr 0.0.0.0> <ms-dns1 0.0.0.0> <ms-dns2 0.0.0.0>]
rcvd [IPCP ConfNak id=0x4 <addr 117.231.135.142> <ms-dns1 218.248.241.3> <ms-dns2 218.248.241.4>]
sent [IPCP ConfReq id=0x5 <addr 117.231.135.142> <ms-dns1 218.248.241.3> <ms-dns2 218.248.241.4>]
rcvd [IPCP ConfAck id=0x5 <addr 117.231.135.142> <ms-dns1 218.248.241.3> <ms-dns2 218.248.241.4>]
Could not determine remote IP address: defaulting to 10.64.64.64
local  IP address 117.231.135.142
remote IP address 10.64.64.64
primary   DNS address 218.248.241.3
secondary DNS address 218.248.241.4
Hangup (SIGHUP)
Connect time 11.4 minutes.
Sent 48700 bytes, received 706943 bytes.
sent [LCP TermReq id=0x2 "User request"]
rcvd [LCP TermAck id=0x2]
Connection terminated.


Here is the complete set of entries seen in /var/log/messages

Mar 14 13:33:14 x53u pppd[612]: pppd options in effect:
Mar 14 13:33:14 x53u pppd[612]: debug        # (from /etc/ppp/peers/bsnl3g)
Mar 14 13:33:14 x53u pppd[612]: persist        # (from /etc/ppp/peers/bsnl3g)
Mar 14 13:33:14 x53u pppd[612]: logfile ppp.log        # (from /etc/ppp/peers/bsnl3g)
Mar 14 13:33:14 x53u pppd[612]: dryrun        # (from command line)
Mar 14 13:33:14 x53u pppd[612]: noauth        # (from /etc/ppp/peers/bsnl3g)
Mar 14 13:33:14 x53u pppd[612]: user x53u        # (from /etc/ppp/peers/bsnl3g)
Mar 14 13:33:14 x53u pppd[612]: password ??????        # (from /etc/ppp/peers/bsnl3g)
Mar 14 13:33:14 x53u pppd[612]: /dev/ttyU0        # (from /etc/ppp/peers/bsnl3g)
Mar 14 13:33:14 x53u pppd[612]: 460800        # (from /etc/ppp/peers/bsnl3g)
Mar 14 13:33:14 x53u pppd[612]: connect /usr/pkg/sbin/chat -v -f /etc/ppp/peers/bsnl3g.chat        # (from /etc/ppp/peers/bsnl3g)
Mar 14 13:33:14 x53u pppd[612]: local        # (from /etc/ppp/peers/bsnl3g)
Mar 14 13:33:14 x53u pppd[612]: novj        # (from /etc/ppp/peers/bsnl3g)
Mar 14 13:33:14 x53u pppd[612]: noipdefault        # (from /etc/ppp/peers/bsnl3g)
Mar 14 13:33:14 x53u pppd[612]: defaultroute        # (from /etc/ppp/peers/bsnl3g)
Mar 14 13:33:14 x53u pppd[612]: usepeerdns        # (from /etc/ppp/peers/bsnl3g)
Mar 14 13:33:14 x53u pppd[612]: Exit.
Mar 14 13:33:54 x53u pppd[477]: pppd 2.4.4 started by root, uid 0
Mar 14 13:33:54 x53u chat[258]: abort on (NO CARRIER)
Mar 14 13:33:54 x53u chat[258]: abort on (NO DIALTONE)
Mar 14 13:33:54 x53u chat[258]: abort on (NO ANSWER)
Mar 14 13:33:54 x53u chat[258]: abort on (DELAYED)
Mar 14 13:33:54 x53u chat[258]: abort on (ERROR)
Mar 14 13:33:54 x53u chat[258]: abort on (BUSY)
Mar 14 13:33:54 x53u chat[258]: send (^MAT^M)
Mar 14 13:33:54 x53u chat[258]: send (ATZ^M)
Mar 14 13:33:54 x53u chat[258]: expect (OK)
Mar 14 13:33:54 x53u chat[258]: ^M
Mar 14 13:33:54 x53u chat[258]: OK
Mar 14 13:33:54 x53u chat[258]:  -- got it
Mar 14 13:33:54 x53u chat[258]: send (AT+CGDCONT=1,"IP","bsnlnet"^M)
Mar 14 13:33:55 x53u chat[258]: expect (OK)
Mar 14 13:33:55 x53u chat[258]: ^M
Mar 14 13:33:55 x53u chat[258]: ^M
Mar 14 13:33:55 x53u chat[258]: OK
Mar 14 13:33:55 x53u chat[258]:  -- got it
Mar 14 13:33:55 x53u chat[258]: send (ATDT*99#^M)
Mar 14 13:33:55 x53u chat[258]: timeout set to 30 seconds
Mar 14 13:33:55 x53u chat[258]: expect (CONNECT)
Mar 14 13:33:55 x53u chat[258]: ^M
Mar 14 13:33:55 x53u chat[258]: ^M
Mar 14 13:33:55 x53u chat[258]: CONNECT
Mar 14 13:33:55 x53u chat[258]:  -- got it
Mar 14 13:33:55 x53u chat[258]: send (^M)
Mar 14 13:33:55 x53u pppd[477]: Serial connection established.
Mar 14 13:33:55 x53u pppd[477]: Using interface ppp0
Mar 14 13:33:55 x53u pppd[477]: Connect: ppp0 <--> /dev/ttyU0
Mar 14 13:33:56 x53u pppd[477]: CHAP authentication succeeded: Welcome!!
Mar 14 13:33:56 x53u pppd[477]: CHAP authentication succeeded
Mar 14 13:33:58 x53u pppd[477]: Could not determine remote IP address: defaulting to 10.64.64.64
Mar 14 13:33:58 x53u pppd[477]: local  IP address 117.231.135.142
Mar 14 13:33:58 x53u pppd[477]: remote IP address 10.64.64.64
Mar 14 13:33:58 x53u pppd[477]: primary   DNS address 218.248.241.3
Mar 14 13:33:58 x53u pppd[477]: secondary DNS address 218.248.241.4
Mar 14 13:45:20 x53u pppd[477]: Hangup (SIGHUP)
Mar 14 13:45:20 x53u pppd[477]: Connect time 11.4 minutes.
Mar 14 13:45:20 x53u pppd[477]: Sent 48700 bytes, received 706943 bytes.
Mar 14 13:45:20 x53u pppd[477]: Connection terminated.


i shutdown the connection by sending a SIGHUP signal.

# kill -1 477

The connection for the entire session was stable and the patch seemed to do its job.

There is scope for improvement:
  • entries in the options file (bsnl3g)
  • entries in the chat script file (bsnl3g.chat).
  • automatically add DNS nameserver entries to the /etc/resolv.conf file
  • if-up and if-down scripts
  • tweak the modem settings (eg. based on AT&CSQ data)
  • explore option to save options on the 3G SIM card without running into PIN invalidation issues.
However, i am currently happy with the Huawei E171 3G USB modem working on NetBSD-current. Huawei modems are redistributed by BSNL to so many people and this patch will be helpful, in case any of them decide to try NetBSD.

Thank you Kimihiro san for the help !

0

阅读 评论 收藏 转载 喜欢 打印举报
已投稿到:
  • 评论加载中,请稍候...
发评论

       

    验证码: 请点击后输入验证码 收听验证码

    发评论

    以上网友发言只代表其个人观点,不代表新浪网的观点或立场。

      

    新浪BLOG意见反馈留言板 不良信息反馈 电话:4006900000 提示音后按1键(按当地市话标准计费) 欢迎批评指正

    新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 会员注册 | 产品答疑

    新浪公司 版权所有