mcphail/linux_huawei_unlocker

Sucessfully unlocked E1750 (Viettel Vietnamese network)

function1983 opened this issue · 9 comments

Thank you so much for the project.

Just want to assure that your code works fine. It took me several hard hours try to figure out why #17 and #18 only solve half of my problem.

My E1750 (which I got about 10 years ago) is locked to one network provider. Running your code will spit out broken pipe trying to connect to ttyUSB1 and ttyUSB2.

I want to share my solution here. Hope it helps others. My guess is that some providers, like mine, will ask Huawei to immediately disconnect the device if not suitable sim card is detected.

==== THE WRONG WAY ====

  1. I plugged in another provider's sim card.
  2. Plug the usb in.
  3. Run usb_modeswitch.
    The computer will still "see" E1750 but there is no way your code will be able to write to the device. When I run

func@func:~$ dmesg | grep tty
[ 0.000000] console [tty0] enabled
[ 0.876305] 00:04: ttyS0 at I/O 0x3f8 (irq = 4, base_baud = 115200) is a 16550A
[ 5.703661] usb 1-5: GSM modem (1-port) converter now attached to ttyUSB0
[ 5.703754] usb 1-5: GSM modem (1-port) converter now attached to ttyUSB1
[ 5.704306] usb 1-5: GSM modem (1-port) converter now attached to ttyUSB2
[ 142.438319] option1 ttyUSB0: GSM modem (1-port) converter now disconnected from ttyUSB0
[ 157.432343] option1 ttyUSB1: GSM modem (1-port) converter now disconnected from ttyUSB1
[ 157.432434] option1 ttyUSB2: GSM modem (1-port) converter now disconnected from ttyUSB2
[ 158.020234] usb 1-5: GSM modem (1-port) converter now attached to ttyUSB0
[ 158.088221] usb 1-5: GSM modem (1-port) converter now attached to ttyUSB1
[ 158.108213] usb 1-5: GSM modem (1-port) converter now attached to ttyUSB2
[ 162.516724] option1 ttyUSB0: usb_wwan_indat_callback: resubmit read urb failed. (-2)
[ 162.516729] option1 ttyUSB0: usb_wwan_indat_callback: resubmit read urb failed. (-2)
[ 162.516731] option1 ttyUSB0: usb_wwan_indat_callback: resubmit read urb failed. (-2)
[ 162.518285] option1 ttyUSB0: GSM modem (1-port) converter now disconnected from ttyUSB0
[ 162.576415] option1 ttyUSB1: GSM modem (1-port) converter now disconnected from ttyUSB1
[ 162.576528] option1 ttyUSB2: GSM modem (1-port) converter now disconnected from ttyUSB2
[ 167.220233] usb 1-5: GSM modem (1-port) converter now attached to ttyUSB0
[ 167.304267] usb 1-5: GSM modem (1-port) converter now attached to ttyUSB1
[ 167.348225] usb 1-5: GSM modem (1-port) converter now attached to ttyUSB2
[ 167.373931] option1 ttyUSB0: GSM modem (1-port) converter now disconnected from ttyUSB0
[ 168.172328] option1 ttyUSB1: GSM modem (1-port) converter now disconnected from ttyUSB1
[ 168.172450] option1 ttyUSB2: GSM modem (1-port) converter now disconnected from ttyUSB2
[ 173.188233] usb 1-5: GSM modem (1-port) converter now attached to ttyUSB0
[ 173.252218] usb 1-5: GSM modem (1-port) converter now attached to ttyUSB1
[ 173.284209] usb 1-5: GSM modem (1-port) converter now attached to ttyUSB2
[ 186.516118] option1 ttyUSB0: GSM modem (1-port) converter now disconnected from ttyUSB0

You can clearly see that ttyUSB0 has been disconnected.. Sad!

==== THE CORRECT WAY ====

  1. First plug a valid sim card from the original provider to keep the device connected to your machine.
  2. Do all the usb_modeswitch and any other stuff you need to do to load your device.
  3. Execute the unlock script. Everything should be running as expected.

I am writing this comment to you using the unlocked E1750 dongle via the initially 'unsupported' sim card.
Kudo to you.

Hello,
I can not pass the first step:

> root@tuananh-Vostro-3459:/home/andrew/Downloads# python2 ./unlocker.py
> ********************************************************************************
> 	Huawei modem unlocker
> 	By Neil McPhail and dogbert
> 	This is Free Software as defined by the GNU GENERAL PUBLIC
> 	LICENSE version 2
> ********************************************************************************
> 	This software comes with NO WARRANTY
> 	This software can damage your hardware
> 	Use it at your own risk
> ********************************************************************************
> 	Not all modems can be unlocked with this software.
> 	Users have reported problems with the following devices:
> 		E220, E353
> 	Attempting to unlock these devices with this software is not
> 	recommended. I hope to fix this in a later release.
> ********************************************************************************
> If you wish to proceed, please type YES at the prompt
> >> YES
> Trying to find which port is the active modem connection.
> Please be patient as this can take a while.
> 
> 
> Testing port /dev/ttyUSB1
> 
> An error occurred when probing for active ports.
> This may be because you need to run this program as root.
> root@tuananh-Vostro-3459:/home/andrew/Downloads# 

My OS is Ubuntu 18.04.2 LTS
My dongle is E1750 fixed Viettel carrier
I have install python2.7, python3 (default) and python3.7.3 as well as pySerial

I totally don't know about Linux. I just learn to unlock my modem

Thank for your help
Tuan Anh (Andrew)

Sorry because I'm not familiar with GitHub and Linux. So may be I miss some useful post when I looking for

P/s: I also wish to know about Linux OS and I saw that GitHub is very useful

Thank,
Tuan Anh (Andrew)

As said, the error states that python cannot access the dongle. Either you (i) do not have sufficient privilege to access the device, or (ii) the device disconnected itself when it cannot find a valid sim card.

To fix the first error. Just run the command using sudo prefix. You don't need to use su but su should work just fine.

To fix the second error, you need to put a valid (preferable active) 3/4G Viettel sim card in first. Your dongle most likely disconnected itself when a Viettel sim card is not found.

Mine is also a Viettel branded dongle. What I am saying is yours should work.

Hi function1983,

  1. I entered exactly what you said:
andrew@tuananh-Vostro-3459:~$ cd Downloads
andrew@tuananh-Vostro-3459:~/Downloads$ sudo python2 ./unlocker.py
[sudo] password for andrew: 
********************************************************************************
	Huawei modem unlocker
	By Neil McPhail and dogbert
	This is Free Software as defined by the GNU GENERAL PUBLIC
	LICENSE version 2
********************************************************************************
	This software comes with NO WARRANTY
	This software can damage your hardware
	Use it at your own risk
********************************************************************************
	Not all modems can be unlocked with this software.
	Users have reported problems with the following devices:
		E220, E353
	Attempting to unlock these devices with this software is not
	recommended. I hope to fix this in a later release.
********************************************************************************
If you wish to proceed, please type YES at the prompt
>> YES
Trying to find which port is the active modem connection.
Please be patient as this can take a while.


Testing port /dev/ttyUSB1

An error occurred when probing for active ports.
This may be because you need to run this program as root.
andrew@tuananh-Vostro-3459:~/Downloads$
  1. I inserted a 4G Viettel Sim, then verify by turning off wifi, and connect internet using that Viettel SIM card. After I have verified the connection of my dongle, I disconnect dongle and re-connect the wifi. The result is not improved.

May be I installed the python and pyserial improperly?

What is the output of lsusb?

Did you implement the #18 fix?

Hi function1983,
The output of lsusb:

andrew@tuananh-Vostro-3459:~/Downloads$ lsusb
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 005: ID 8087:07dc Intel Corp.
Bus 001 Device 004: ID 0bda:0129 Realtek Semiconductor Corp. RTS5129 Card Reader Controller
Bus 001 Device 003: ID 0bda:5683 Realtek Semiconductor Corp.
Bus 001 Device 010: ID 045e:0773 Microsoft Corp.
Bus 001 Device 009: ID 12d1:14a9 Huawei Technologies Co., Ltd.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

I really don't understand much about # 15,16,17,18.
I did: copy the codes from # 18, replace to the unlocker.py downloaded from the main page

def identifyPort():
print "Trying to find which port is the active modem connection."
print "Please be patient as this can take a while.\n\n"
for p in glob.glob('/dev/ttyUSB*'):
try:
print "Testing port " + p
ser = serial.Serial(port = p,
timeout = 15)
ser.write('AT\r\n')
activity = ser.read(5)
if activity == '':
print "\tNo activity\n"
ser.close()
continue
except:
print "\tError, This may be because you need to run this program as root.\n"
ser.close()
continue
else:
print "\tActivity detected\n"
ser.close()
return p
return ''

Please teach me about:

  • usb_modeswitch
  • catch exception (how to catch, what is it? How to manually catch?)

I also try:

andrew@tuananh-Vostro-3459:~/Downloads$ python
Python 2.7.15+ (default, Nov 27 2018, 23:36:35)
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.

serial.Serial(port='/dev/ttyUSB1', timeout=15)
Traceback (most recent call last):
File "", line 1, in
NameError: name 'serial' is not defined

The result same:


If you wish to proceed, please type YES at the prompt

YES
Trying to find which port is the active modem connection.
Please be patient as this can take a while.

Testing port /dev/ttyUSB1
Error, This may be because you need to run this program as root.

An error occurred when probing for active ports.
This may be because you need to run this program as root.

Thank you!

Looks like your computer has detected the device, which is a good sign.

Your dongle could act either as an usb storage device or a WAN dongle, but NOT both. usb_modeswitch tells the dongle to switch between the two modes. Default is usb storage.

#18 fix is to tell python to ignore any error message when sending AT command to each usb device and just keep iterating without crashing to terminal after failing the first usb device. CODE HERE. But first, run dmesg | grep tty after usb_modeswitch to see if your device is listed as connected there. Please include the output if you still face the issue.

I replaced the codes from SHOTbyGUN to original unlocker.py then perform:

  1. lsusb
  2. usb_modeswitch
  3. dmesg | grep tty
  4. sudo ./unlocker.py
  5. lsusb

Here are what I did:

andrew@tuananh-Vostro-3459:/Downloads$ lsusb
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 005: ID 8087:07dc Intel Corp.
Bus 001 Device 004: ID 0bda:0129 Realtek Semiconductor Corp. RTS5129 Card Reader Controller
Bus 001 Device 003: ID 0bda:5683 Realtek Semiconductor Corp.
Bus 001 Device 002: ID 045e:0773 Microsoft Corp.
Bus 001 Device 007: ID 12d1:14a9 Huawei Technologies Co., Ltd.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
andrew@tuananh-Vostro-3459:
/Downloads$ usb_modeswitch

Usage: usb_modeswitch [] [-c filename]

-h, --help this help
-e, --version print version information and exit
-j, --find-mbim return config no. with MBIM interface, exit

-v, --default-vendor NUM vendor ID of original mode (mandatory)
-p, --default-product NUM product ID of original mode (mandatory)
-V, --target-vendor NUM target mode vendor ID (optional)
-P, --target-product NUM target mode product ID (optional)
-C, --target-class NUM target mode device class (optional)
-b, --bus-num NUM system bus number of device (for hard ID)
-g, --device-num NUM system device number (for hard ID)
-m, --message-endpoint NUM direct the message transfer there (optional)
-M, --message-content message to send (hex number as string)
-2, --message-content2 additional messages to send (-n recommended)
-3, --message-content3 additional messages to send (-n recommended)
-w, --release-delay NUM wait NUM ms before releasing the interface
-n, --need-response obsolete, no effect (always on)
-r, --response-endpoint NUM read response from there (optional)
-K, --std-eject send standard EJECT sequence
-d, --detach-only detach the active driver, no further action
-H, --huawei-mode apply a special procedure
-J, --huawei-new-mode apply a special procedure
-X, --huawei-alt-mode apply a special procedure
-S, --sierra-mode apply a special procedure
-O, --sony-mode apply a special procedure
-G, --gct-mode apply a special procedure
-N, --sequans-mode apply a special procedure
-A, --mobileaction-mode apply a special procedure
-T, --kobil-mode apply a special procedure
-L, --cisco-mode apply a special procedure
-B, --qisda-mode apply a special procedure
-E, --quanta-mode apply a special procedure
-F, --pantech-mode NUM apply a special procedure, pass NUM through
-Z, --blackberry-mode apply a special procedure
-U, --option-mode apply a special procedure
-R, --reset-usb reset the device after all other actions
-Q, --quiet don't show progress or error messages
-W, --verbose print all settings and debug output
-D, --sysmode specific result and syslog message
-s, --check-success switching result check with timeout
-I, --inquire obsolete, no effect

-c, --config-file load long configuration from file

-t, --stdinput read long configuration from stdin

-f, --long-config get long configuration from string

-i, --interface NUM select initial USB interface (default 0)
-u, --configuration NUM select USB configuration
-a, --altsetting NUM select alternative USB interface setting

  • usb_modeswitch: handle USB devices with multiple modes
  • Version 2.5.2 (C) Josua Dietze 2017
  • Based on libusb1/libusbx

! PLEASE REPORT NEW CONFIGURATIONS !

andrew@tuananh-Vostro-3459:/Downloads$ dmesg | grep tty
[ 0.000000] console [tty0] enabled
[ 6697.090447] usb 1-2: GSM modem (1-port) converter now attached to ttyUSB0
[ 6697.092032] usb 1-2: GSM modem (1-port) converter now attached to ttyUSB1
andrew@tuananh-Vostro-3459:
/Downloads$ sudo ./unlocker.py


Huawei modem unlocker
By Neil McPhail and dogbert
This is Free Software as defined by the GNU GENERAL PUBLIC
LICENSE version 2


This software comes with NO WARRANTY
This software can damage your hardware
Use it at your own risk


Not all modems can be unlocked with this software.
Users have reported problems with the following devices:
E220, E353
Attempting to unlock these devices with this software is not
recommended. I hope to fix this in a later release.


If you wish to proceed, please type YES at the prompt

YES
Trying to find which port is the active modem connection.
Please be patient as this can take a while.

Testing port /dev/ttyUSB1
Error, This may be because you need to run this program as root.

An error occurred when probing for active ports.
andrew@tuananh-Vostro-3459:/Downloads$ lsusb
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 005: ID 8087:07dc Intel Corp.
Bus 001 Device 004: ID 0bda:0129 Realtek Semiconductor Corp. RTS5129 Card Reader Controller
Bus 001 Device 003: ID 0bda:5683 Realtek Semiconductor Corp.
Bus 001 Device 002: ID 045e:0773 Microsoft Corp.
Bus 001 Device 007: ID 12d1:14a9 Huawei Technologies Co., Ltd.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
andrew@tuananh-Vostro-3459:
/Downloads$

I don't confidence for the usb_modeswitch command I entered, it seem do nothing.
Thanks

Hi,
After spent haft of day, I could find the correct way. But unfortunately, my modem is hard locked

andrew@tuananh-Vostro-3459:~/Downloads$ python -m serial.tools.list_ports
/dev/ttyUSB1        
/dev/ttyUSB2        
2 ports found
andrew@tuananh-Vostro-3459:~/Downloads$ sudo ./unlocker.py
********************************************************************************
	Huawei modem unlocker
	By Neil McPhail and dogbert
	This is Free Software as defined by the GNU GENERAL PUBLIC
	LICENSE version 2
********************************************************************************
	This software comes with NO WARRANTY
	This software can damage your hardware
	Use it at your own risk
********************************************************************************
	Not all modems can be unlocked with this software.
	Users have reported problems with the following devices:
		E220, E353
	Attempting to unlock these devices with this software is not
	recommended. I hope to fix this in a later release.
********************************************************************************
If you wish to proceed, please type YES at the prompt
>> YES

Trying to obtain IMEI.
The modem will be given 5 seconds to respond.
Found probable IMEI: 353558047436084
IMEI checksum OK.

Checking the lock status of the SIM.
The modem will be given 5 seconds to respond.

The modem is hard locked,
This program cannot help you.
andrew@tuananh-Vostro-3459:~/Downloads$ 

Thank for your help
Thank for mcphail's code