Huawei E3531 configuration Raspbian Jessie – pppd

In the previous post huawei-e3531-configuration-raspbian-jessie I got usb_modeswitch running to change the mode of the usb dongle into modem mode on insertion or reboot. This post is a continuation on the previous post to configure pppd to use the usb dongle as a modem and set up a point to point connection to the internet, or at least the mobile provider. When using a tutorial found online it didn’t work first time. A problem setting up the connection is described with logfiles and attempts to diagnose the problem, then the solution is provided. This solution is most likely specific to o2(uk). The final section describes the configuration file used just to get pppd working with o2. Networking is not covered since once the connection is established there are many ways you can configure routing, firewalls and VPN to name a few. An example use for this is you can configure hostapd and dnsmasq to provide a mobile broadband hotspot.

Following the advice on [Insert Link here, unknown source], when trying to the connect the connection would fail to come up. On checking /var/log/syslog I was getting the following PAP authentication succeeded but then the modem would hang up immediately afterwards:

Dec 24 12:54:28 raspberrypi pppd[9435]: Serial connection established.
Dec 24 12:54:28 raspberrypi pppd[9435]: Using interface ppp0
Dec 24 12:54:28 raspberrypi pppd[9435]: Connect: ppp0 <--> /dev/ttyUSB0
Dec 24 12:54:29 raspberrypi pppd[9435]: Remote message: Greetings!!
Dec 24 12:54:29 raspberrypi pppd[9435]: PAP authentication succeeded
Dec 24 12:54:29 raspberrypi pppd[9435]: LCP terminated by peer
<strong>Dec 24 12:54:29 raspberrypi pppd[9435]: Hangup (SIGHUP)</strong>
Dec 24 12:54:29 raspberrypi pppd[9435]: Modem hangup
Dec 24 12:54:29 raspberrypi pppd[9435]: Connection terminated.

This logfile isn’t very descriptive, luckily you can enable debugging by adding the “debug” option to the end of the pppd configuration file. The one I was using was located in: /etc/ppp/peers/gprs. I also changed the authentication to CHAP but this had no success. Below is the logfile with debugging enabled.

Dec 26 18:56:21 raspberrypi pppd[10226]: Using interface ppp0
Dec 26 18:56:21 raspberrypi pppd[10226]: Connect: ppp0 &lt;--&gt; /dev/ttyUSB0
Dec 26 18:56:22 raspberrypi pppd[10226]: sent [LCP ConfReq id=0x2 &lt;asyncmap 0x0&gt; &lt;magic 0x55b552f8&gt; &lt;pcomp&gt; &lt;accomp&gt;]
Dec 26 18:56:22 raspberrypi pppd[10226]: rcvd [LCP ConfReq id=0x1 &lt;accomp&gt; &lt;pcomp&gt; &lt;asyncmap 0x0&gt; &lt;mru 1500&gt; &lt;magic 0x54d&gt; &lt;auth chap MD5&gt;]
Dec 26 18:56:22 raspberrypi pppd[10226]: sent [LCP ConfAck id=0x1 &lt;accomp&gt; &lt;pcomp&gt; &lt;asyncmap 0x0&gt; &lt;mru 1500&gt; &lt;magic 0x54d&gt; &lt;auth chap MD5&gt;]
Dec 26 18:56:22 raspberrypi pppd[10226]: rcvd [LCP ConfAck id=0x2 &lt;asyncmap 0x0&gt; &lt;magic 0x55b552f8&gt; &lt;pcomp&gt; &lt;accomp&gt;]
Dec 26 18:56:22 raspberrypi pppd[10226]: sent [LCP EchoReq id=0x0 magic=0x55b552f8]
Dec 26 18:56:22 raspberrypi pppd[10226]: rcvd [CHAP Challenge id=0x1 &lt;6a72fdb6d5e382736072d083cdd069ea&gt;, name = "HUAWEI_CHAP_SRVR"]
Dec 26 18:56:22 raspberrypi pppd[10226]: sent [CHAP Response id=0x1 &lt;b30763faefba7325481226d08eeb2fb8&gt;, name = "o2web"]
Dec 26 18:56:22 raspberrypi pppd[10226]: rcvd [LCP EchoRep id=0x0 magic=0x54d]
Dec 26 18:56:22 raspberrypi pppd[10226]: rcvd [CHAP Success id=0x1 "Welcome!!"]
Dec 26 18:56:22 raspberrypi pppd[10226]: CHAP authentication succeeded: Welcome!!
Dec 26 18:56:22 raspberrypi pppd[10226]: CHAP authentication succeeded
Dec 26 18:56:22 raspberrypi pppd[10226]: sent [CCP ConfReq id=0x2 &lt;deflate 15&gt; &lt;deflate(old#) 15&gt; &lt;bsd v1 15&gt;]
Dec 26 18:56:22 raspberrypi pppd[10226]: sent [IPCP ConfReq id=0x2 &lt;compress VJ 0f 01&gt; &lt;addr 0.0.0.0&gt; &lt;ms-dns1 0.0.0.0&gt; &lt;ms-dns2 0.0.0.0&gt;]
Dec 26 18:56:22 raspberrypi pppd[10226]: rcvd [IPCP ConfReq id=0x1]
Dec 26 18:56:22 raspberrypi pppd[10226]: sent [IPCP ConfNak id=0x1 &lt;addr 0.0.0.0&gt;]
Dec 26 18:56:22 raspberrypi pppd[10226]: rcvd [LCP ProtRej id=0x2 80 fd 01 02 00 0f 1a 04 78 00 18 04 78 00 15 03 2f]
Dec 26 18:56:22 raspberrypi pppd[10226]: Protocol-Reject for 'Compression Control Protocol' (0x80fd) received
<strong>Dec 26 18:56:22 raspberrypi pppd[10226]: Hangup (SIGHUP)</strong>
Dec 26 18:56:22 raspberrypi pppd[10226]: rcvd [LCP TermReq id=0x2]
Dec 26 18:56:22 raspberrypi pppd[10226]: LCP terminated by peer
Dec 26 18:56:22 raspberrypi pppd[10226]: sent [LCP TermAck id=0x2]
Dec 26 18:56:22 raspberrypi pppd[10226]: Modem hangup
Dec 26 18:56:22 raspberrypi pppd[10226]: Connection terminated.

It looks like “Protocol-Reject for ‘Compression Control Protocol’ (0x80fd) received” is causing the hangup. After trying additional options in /etc/ppp/peers/ to disable compression it seemed like this made things worse by not trying to negotiate over LCP and ending the connection sooner. The additional options used are listed below, these all resulted in no success but sometimes the modem would connect and provide a link! On reboot or reconnecting it would not reliably connect.

novj
lock
crtscts
modem
passive
holdoff 10
maxfail 0
novjccomp
nopcomp
nodeflate

The solution

In the default chatscript /etc/chatscript/gprs there is a line to dial in data mode:

OK ATD*99#

It turns out for o2 this should be:

OK ATD*99***2#

After changing that line connection attempts succeeded consistently.

Configuration files

This section describes all the configuration used to get a connection working with the E3531 and o2 uk pay as you go.

The first configuration is to install pppd the usual way (apt-get ppp). Once this has completed a ppp configuration need to be established. The default file located in /etc/ppp/peers/gprs does a good job. Each configuration file in the peers directory represents a different connection. There can be multiple peers to connect to that you can configure in this directory. My gprs configuration for o2 is listed below.

# example configuration for a dialup connection authenticated with PAP or CHAP
#
# This is the default configuration used by pon(1) and poff(1).
# See the manual page pppd(8) for information on all the options.

# MUST CHANGE: replace myusername@realm with the PPP login name given to
# your by your provider.
# There should be a matching entry with the password in /etc/ppp/pap-secrets
# and/or /etc/ppp/chap-secrets.
user "payandgo"
password "wap"

# MUST CHANGE: replace ******** with the phone number of your provider.
# The /etc/chatscripts/pap chat script may be modified to change the
# modem initialization string.
connect "/usr/sbin/chat -v -f /etc/chatscripts/gprs -T payandgo.o2.co.uk"

# Serial device to which the modem is connected.
/dev/ttyUSB0

# Speed of the serial line.
921600

# Assumes that your IP address is allocated dynamically by the ISP.
noipdefault
# Try to get the name server addresses from the ISP.
usepeerdns
# Use this connection as the default route.
defaultroute

# Makes pppd "dial again" when the connection is lost.
persist

# Do not ask the remote to authenticate.
noauth

The user and password at the top of the configuration seems to bypass the secrets file despite the comment “There should be a matching entry with the password in /etc/ppp/pap-secrets and/or /etc/ppp/chap-secrets.” In my configuration this is ignored.

The connect line gets /usr/sbin/chat to send AT commands to the modem pointed to at /dev/ttyUSB0.  The -v option enables verbose logging in syslog (you can probably omit this). The -f option provides the chatfile described below. The -T option provides additional arguments to the chatscript. In the comments this is described as the phone number but in 3G this is the APN that o2 uses for pay as you go connections, payandgo.o2.co.uk.

noipdefault obtains an ip address from o2 although during the connection negotiation it seems to default to 10.164.164.164.

defaultroute adds o2 as the default route and noauth is ok to leave.

As mentioned before the chatscript sets up the modem and “dials”, this is where the number needed to change from the default script /etc/chatscripts/gprs

# You can use this script unmodified to connect to cellular networks.
# The APN is specified in the peers file as the argument of the -T command
# line option of chat(8).

# For details about the AT commands involved please consult the relevant
# standard: 3GPP TS 27.007 - AT command set for User Equipment (UE).
# (http://www.3gpp.org/ftp/Specs/html-info/27007.htm)

ABORT BUSY
ABORT VOICE
ABORT "NO CARRIER"
ABORT "NO DIALTONE"
ABORT "NO DIAL TONE"
ABORT "NO ANSWER"
ABORT "DELAYED"
ABORT "ERROR"

# cease if the modem is not attached to the network yet
ABORT "+CGATT: 0"

"" AT
TIMEOUT 12
OK ATH
OK ATE1

# +CPIN provides the SIM card PIN
#OK "AT+CPIN=1234"

# +CFUN may allow to configure the handset to limit operations to
# GPRS/EDGE/UMTS/etc to save power, but the arguments are not standard
# except for 1 which means "full functionality".
OK AT+CFUN=1,1

OK AT+CGDCONT=1,"IP","\T","",0,0
OK ATD*99***2#
TIMEOUT 22
CONNECT ""

The final configuration is required in /etc/network/interfaces.

auto gprs
iface gprs inet ppp
&nbsp; &nbsp; provider gprs

The ppp tells networking to use pppd with the configuration given by the provider option. I could be wrong but this seems equivalent to networking calling pppd call gprs where gprs is the options file given in /etc/ppp/peers/gprs describing the individual connection. If you had multiple connections you could use provider conn1 …etc.

All the configuration required is complete. Run ifup gprs to start connecting to the mobile broadband modem.

On reboot this doesn’t seem to automatically connect on boot and nothing in syslog seems to shed light on why. Ifup is required to get the connection going again but a script could be added in a udev rule for when the ttyUSB0 comes online, that’s for another day.

Conclusion

That concludes this two part post on using the E3531 Huawei dongle as a modem with o2 pay as you go. I’m sure this can be applied to other networks with different APN, user and password setting along with the ATD number.

Note: This usb modem and ppp was configured with raspbian jessie lite, at the time of writing raspbian stretch was available and it had not been verified that the usb_modeswitch fix in the first post was still necessary. If you try this with raspbian stretch you may find that usb_modeswitch works correctly when the modem is inserted the first time.

Leave a Reply