Skip to content

Instantly share code, notes, and snippets.

@smarek
Last active July 5, 2024 19:59
Show Gist options
  • Save smarek/cbe2ae6f9bcd76d610c013668df880e5 to your computer and use it in GitHub Desktop.
Save smarek/cbe2ae6f9bcd76d610c013668df880e5 to your computer and use it in GitHub Desktop.
E3372s-153 from Stick mode to HiLink mode automatic installer

E3372s from STICK to HiLink mode installer

You need

  • curl, usb-modeswitch, grep, awk, sudo (not necessary, last step can fail safely)
  • balong_flash in $PATH ( https://github.com/forth32/balongflash.git )
  • atinout in $PATH ( https://github.com/beralt/atinout.git will work fine )
  • 2 files we flash (core sw update version 22.x, WebUI installer), we use these (you can probably use different balong-compatible):
    • core sw: "E3372sUpdate_22.298.03.02.965.BIN" / "E3372sUpdate_22.298.03.02.965.exe"
    • webui: "Update_WEBUI_17.100.06.00.03_Hilink_V7R2_9x25_CPIO.exe"

Scripts handle these situations:

  • Taking the device from storage/cd-rom mode to correct flashing mode (godload)
  • Taking the device from debug mode to correct flashing mode (godload)
  • Handling special state, where 12d1:1442 ttyUSB0 provides AT-mode instead of correct godload
  • Handling, when the device is hi-link but has no UI (see part with curl POST xml to /CGI)

Step-by-step

  • (Optional) put 70-huawei-e3.rules and huawei_e3.conf in correct places for UDEV usb-modeswitch and reload-rules/restart-computer
  • Put all files into one folder, together with firmware 22.x and WebUI updates
  • Plug the E3372s-153 in stick-mode to USB, and wait for it to appear in lsusb
  • Run ./auto_install.sh, observe output
  • If everything runs correctly, the modem will restart itself, script will set it up with ifconfig/dhclient, and web interface should be on address http://192.168.8.1/

WARNING, this is alpha version of scripts, everything you do is on your risk, i do not take any responsibility

# place in /etc/udev/rules.d/70-huawei-e3.rules
SUBSYSTEM=="usb", ACTION=="add", ATTRS{idVendor}=="12d1", ATTRS{idProduct}=="1f01", RUN+="/usr/sbin/usb_modeswitch -c /etc/usb_modeswitch.d/huawei_e3.conf"
SUBSYSTEM=="usb", ACTION=="add", ATTRS{idVendor}=="12d1", ATTRS{idProduct}=="14fe", RUN+="/usr/sbin/usb_modeswitch -c /etc/usb_modeswitch.d/huawei_e3.conf"
SUBSYSTEM=="net", ACTION=="add", ATTRS{idVendor}=="12d1", ATTRS{idProduct}=="14dc", NAME="usb0"
#!/bin/bash
echo () {
bash -c "echo [E3372s stick-to-hilink] $1"
}
IS_14FE=$(lsusb | grep 12d1\:14fe | wc -l)
if [ "$IS_14FE" == "1" ] ; then
echo "14FE (mass-storage), switching to 1506 (AT mode)"
usb_modeswitch --verbose -J -v 0x12d1 -p 0x14fe
sleep 5
else
echo "14FE not found, not switching"
fi
IS_1506=$(lsusb | grep 12d1\:1506 | wc -l)
IS_1C05=$(lsusb | grep 12d1\:1c05 | wc -l)
IS_14DC=$(lsusb | grep 12d1\:14dc | wc -l)
IS_1566=$(lsusb | grep 12d1\:1566 | wc -l)
if [ "$IS_1506" == "1" ] || [ "$IS_1566" == "1" ] ; then
echo "1506/1566 to godload"
./godload.sh
elif [ "$IS_1C05" == "1" ] ; then
echo "already in godload, not switching"
elif [ "$IS_14DC" == "1" ] ; then
echo "in hi-link mode, switching back to debug"
sudo ifconfig usb0 up
sudo dhclient usb0
sleep 3
timeout 3 curl -X POST -d @sw_debug_mode.xml http://192.168.8.1/CGI
sleep 6
./godload.sh
fi
IS_1C05=$(lsusb | grep 12d1\:1c05 | wc -l)
IS_1442=$(lsusb | grep 12d1\:1442 | wc -l)
if [ "$IS_1C05" == "1" ] ; then
balong_flash -p /dev/ttyUSB2 -gd E3372sUpdate_22.298.03.02.965.BIN
sleep 15
elif [ "$IS_1442" == "1" ] ; then
echo "skip, 1442 means 1st balong flash already passed"
else
echo "not in godload mode, exiting"
exit 1
fi
IS_1506=$(lsusb | grep 12d1\:1506 | wc -l)
IS_1442=$(lsusb | grep 12d1\:1442 | wc -l)
if [ "$IS_1506" == "1" ] && [ "$IS_1442" == "0" ] ; then
echo "1506 to godload"
./godload.sh
elif [ "$IS_1442" == "1" ] ; then
echo "skip, 1442 means we are still in godload mode"
else
echo "not 1506 after balong_flash, something went wrong"
exit 1
fi
IS_USB0_AT=$(timeout 5 bash -c "echo 'AT' | atinout - /dev/ttyUSB0 - | grep OK | wc -l")
IS_USB0_AT=$(timeout 5 bash -c "echo 'AT' | atinout - /dev/ttyUSB0 - | grep OK | wc -l")
if [ "$IS_USB0_AT" == "1" ] ; then
./godload.sh
fi
sleep 5
IS_1C05=$(lsusb | grep 12d1\:1c05 | wc -l)
IS_1442=$(lsusb | grep 12d1\:1442 | wc -l)
if [ "$IS_1C05" == "1" ] || [ "$IS_1442" == "1" ] ; then
balong_flash -p /dev/ttyUSB0 -gd Update_WEBUI_17.100.06.00.03_Hilink_V7R2_9x25_CPIO.exe
sleep 15
else
echo "not 1C05 after godload, something went wrong"
exit 1
fi
IS_1F01=$(lsusb | grep 12d1\:1f01 | wc -l)
if [ "$IS_1F01" == "1" ] ; then
usb_modeswitch --verbose -J -v 0x12d1 -p 0x1f01
sleep 5
else
echo "not 1F01 after balong_flash, maybe already automatically usb-modeswitched?"
fi
IS_14DC=$(lsusb | grep 12d1\:14dc | wc -l)
if [ "$IS_14DC" == "1" ] ; then
sudo ifconfig usb0 up
ps aux | grep -i dhclient\ usb0 | awk '{print $2}' | xargs -L1 sudo kill -9
sudo dhclient usb0
./device_info.sh
fi
exit 0
#!/bin/sh
MODEM_IP="192.168.8.1"
curl -s -X GET "http://$MODEM_IP/api/webserver/SesTokInfo" > /tmp/ses_tok.xml
COOKIE=`grep "SessionID=" /tmp/ses_tok.xml | cut -b 10-147`
TOKEN=`grep "TokInfo" /tmp/ses_tok.xml | cut -b 10-41`
curl -s -X GET "http://$MODEM_IP/api/device/information" \
-H "Cookie: $COOKIE" -H "__RequestVerificationToken: $TOKEN" \
-H "Content-Type: text/xml"
# in case of broken MTD16 (data) partition, will print out error 100002
curl -s -X GET "http://$MODEM_IP/api/dialup/profiles" \
-H "Cookie: $COOKIE" -H "__RequestVerificationToken: $TOKEN" \
-H "Content-Type: text/xml"
#!/bin/bash
at() {
timeout 1 echo "$1" | atinout - /dev/ttyUSB0 -
}
echo "[godload] startup"
at "AT"
sleep 1
at "AT"
sleep 1
at "AT^GODLOAD"
echo "[godload] waiting 10 sec"
sleep 10
# place in nano /etc/usb_modeswitch.d/huawei_e3.conf
TargetVendor=0x12d1
TargetProductList="14db,14dc"
HuaweiNewMode=1
NoDriverLoading=1
DefaultVendor=0x12d1
DefaultProduct=0x1f01
<?xml version="1.0" encoding="UTF-8" ?>
<api version="1.0">
<header>
<function>switchMode</function>
</header>
<body>
<request>
<switchType>1</switchType>
</request>
</body>
</api>
@neftaly
Copy link

neftaly commented Oct 4, 2018

Thanks for putting this up!

@deb75
Copy link

deb75 commented Feb 14, 2021

Hi,

I would like to perform the opposite, I have one e3372s-153 in hilink mode and I would like to turn in to stick mode.

I know it is possible to do so, there are several tutorials using the same tool for the e3372h-153.

However, the main trouble is to make devices /dev/ttyUSB[0,1,2] appear. When in hilink mode you do not have these by default.
On some tutorials, they show how to make them appear by shorting some pins with a needle. I tried on my e3372s-153 and nothing
showed up.

Do you know how I could proceed ?

Regards

@Ierlandfan
Copy link

On line 31 it uses an xml which is not valid in newer firmwares and you need the session token. Both can be found. I wil try in the coming days to modify the script since I am in the same boat. The needle part didn't worked for me but there's a way easier way. If in hurry search for xml api hilink and request.

@makedir
Copy link

makedir commented Jan 30, 2024

root@Ubuntu64:/home/vboxuser/flashhilink# ./auto_install.sh

[E3372s stick-to-hilink] 14FE not found, not switching

[E3372s stick-to-hilink] 1506/1566 to godload

[godload] startup

+CME ERROR: 10

what now?

root@Ubuntu64:/home/vboxuser/flashhilink# lsusb

Bus 002 Device 003: ID 12d1:1506 Huawei Technologies Co., Ltd. Modem/Networkcard


So the above happens if you have no SIM card in the stick, so the flashing doesnt work without SIM card inserted, that should have told in the tutorial.

With SIM card, I am still stuck though, that there is not /dev/ttyUSB2 device after godmode switch. My USB id changes though from

12d1:1506 to
12d1:1c05

and the led starts to blink quickly with no pause anymore. Anyone know whats going wrong? flashing the bin file stops because of no /dev/ttyUSB2 device

dmesg after godload:

[ 142.205823] usb 2-1: New USB device found, idVendor=12d1, idProduct=1c05, bcdDevice= 1.02
[ 142.205828] usb 2-1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[ 142.205830] usb 2-1: Product: HUAWEI_MOBILE
[ 142.205831] usb 2-1: Manufacturer: HUAWEI_MOBILE
[ 142.261131] option 2-1:1.0: GSM modem (1-port) converter detected
[ 142.261240] usb 2-1: GSM modem (1-port) converter now attached to ttyUSB0
[ 142.275407] usb-storage 2-1:1.1: USB Mass Storage device detected
[ 142.275640] scsi host3: usb-storage 2-1:1.1
[ 142.275753] option 2-1:1.2: GSM modem (1-port) converter detected
[ 142.276955] usb 2-1: GSM modem (1-port) converter now attached to ttyUSB1
[ 143.482792] scsi 3:0:0:0: CD-ROM HUAWEI Mass Storage 2.31 PQ: 0 ANSI: 2
[ 143.492841] sr 3:0:0:0: Power-on or device reset occurred
[ 143.520293] sr 3:0:0:0: [sr1] scsi-1 drive
[ 143.530768] sr 3:0:0:0: Attached scsi CD-ROM sr1
[ 143.530976] sr 3:0:0:0: Attached scsi generic sg2 type 5

no 3rd ttyUSB2 device

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment