Showing posts with label xiaomi. Show all posts
Showing posts with label xiaomi. Show all posts

Saturday, March 3, 2018

Step-by-Step: Install OpenWRT on the Xiaomi Wifi Mini router from a Windows Computer (2018 edition)

The Xiaomi Mini wifi router has a low price and spacious ROM (16MB) and RAM (128MB) for easily supporting a VPN service on a OpenWRT/LEDE installation.  Thanks to the hard work by the community it’s fairly straight-forward to replace the Stock OEM firmware with LEDE.

PREREQUISITES

A. A computer with a web browser for downloading the files, registering a Xiaomi account, and capable of running SSH.

B. The LEDE Installation File from | download.openwrt.org

  • miwifi-mini-squashfs-sysupgrade.bin

C. A Xiaomi Account for registering the router | https://account.xiaomi.com/pass/register

D.  The Developer edition of the Router ROM from Xiaomi | http://www.miwifi.com/miwifi_download.html

  • Click the ROM graphic, scroll down to find “ROM for Mini 开发版


Xiaomi Developer ROM download for Mi MINI Router

E. A mobile device with Xiaomi’s router app installed | Google Play Link | Xiaomi APK

F. The customized SSH BIN file from Xiaomi.  This file can only be downloaded after registering the router with the Router app on your phone or tablet and it’s unique to each router since the ROOT password is apparently baked into it | Xiaomi SSH Site

G. A physical Ethernet connection to the router’s LAN ports (white colored).  Note: You can do most of the process on Wifi, but not all of it, so I recommend starting with Ethernet to simplify the process.

H. A USB drive formatted to FAT32 for installing the SSH BIN and LEDE BIN files to the router. The file is small, so the USB drive doesn't have to be big.

I. PuTTY for Windows to run SSH commands | Download page

Initial Setup of the Router

1. Connect a network patch cable from your Internet equipment to the WAN Uplink port (blue colored).
2. Connect a Windows computer to one of the Ethernet switch ports on the router (white colored).
3. Connect the router to power.
4. Launch a web browser and connect to the administrator console by going to the following address:
http://192.168.31.1, If you cannot reach the administrator console:

  • Check the IP address on your computer and verify the it starts with 192.168.31
  • Verify that you have any VPN software running on your computer that it is turned OFF
  • Verify that the OS Proxy settings are disabled in “Internet Options”

5. Follow the setup wizard and configure the router.

  • Note: It will ask you to set the wifi and the administrator password. Set it to 1234567890
  • Note: All settings made during this process will be erased later, so don’t spend time making it nice...

After you complete the setup wizard, the router will reboot.

Unlock the Router's Firmware

1. Download the "Developer" ROM from Xiaomi, if you haven’t already (see pre-reqs step D).
2. Manually flash the Developer ROM through the web app console.  (Select the 3rd tab option, select the last menu item, and click the first command button to upload the file, click the right-hand button to confirm the installation of the new ROM. (It’s all in Chinese, so I’m trying to be helpful here, not condescending :-)

4. Install the Mi Wifi app on a mobile device (see pre-reqs step E)

5. Connect your mobile device to the Xiaomi MINI's wifi network

6. Sign-in to the mobile app with a "Mi" account or create a new one and then sign in. As of this writing, no personal information is needed other than an email account.

7. The app should detect the router.  Sign into the Wifi Router inside the app using the admin password you set during setup (in this example we set it to 1234567890) .  The router should now be registered to your Xiaomi account, our “Bound” as Google Translate says.

8. Download the the SSH BIN patch file at https://d.miwifi.com/rom/ssh. It's supposed to be custom and unique for your router, so I'm imagining it's because the BIN files needs your router's root password baked in.

<screenshot>

9. While you're at the Xiaomi SSH site copy down the "root" password from the page; you’ll need it for SSH later.

<screenshot>

10. Copy the miwifi_ssh.bin file from your computer to a USB drive formatted with FAT32.

11. Insert this USB drive into the USB port on the back of the Xiaomi router

12. Unplug the router's power cable.

13. Use a tool (like a straightened paperclip) to press down the reset button on the back of the router and hold it in.  While keeping the button pressed down, reconnect the power cable...not a task for the manually challenged. The yellow status light will come on at the front of the router. After about 10 seconds the yellow status light will begin to blink indicating that the router is now installing the SSH BIN file.  Once the yellow light is flashing like this you can release the reset button.

14. After the SSH file is installed, the router will reboot and the yellow light will become steady again during the boot process.  After the router is done booting, the status LED will turn a steady "blue" color.

15. Sign into the router using PuTTY on your Windows computer, using SSH (not Telnet) and enter the enter the root password from the Xiaomi website


  • Note: On Linux, you can run ssh root@192.168.31.1 (this command works on a Windows computer as well if you've installed OpenSSH for Powershell from github)

<screenshot>

You're in! Enjoy your new super powers wisely

Install OpenWRT Stable Edition

1. Download the following LEDE BIN files from the Stable tree | Download Page (see pre-reqs step B)

2. Remove the USB drive from the router, copy the BIN file to it, and then re-insert the USB drive back into the router.

3.  Within the SSH console in PuTTY, use these commands check the MTD layout on the router to make sure you don't damage it:

cat /proc/mtd

4. If you find a line "OS1" in the text output from this command go ahead with flashing:

cd /extdisks/sda1

ls

5. Verify that the BIN file is in this directory from the text output. If it is, flash the ROM:

mtd -r write /extdisks/sda1/lede-17.01.4-ramips-mt7620-miwifi-mini-squashfs-sysupgrade.bin OS1

After flashing is complete, the router will reboot several times. It can seem to take a long time and interrupting the process can damage your router, so wait about 10 minutes to ensure that the firmware is installed properly before doing anything to the router.  The WebUI is not always accessible on first boot after all of the flashing steps, so power off the router and power it back-on by disconnecting the power plug and plugging it back in.

Also, please note that the OpenWRT OS defaults to the red color of the led instead of the orange/blue during and after finishing the boot that Xiaomi uses. (Need to double-check this with the newest build)

You're now running OpenWRT! Enjoy your more secure and flexible router.


REFERENCES

Xiaomi SSH Website After Registering Your Device in the App

小米ID:0000000000
已绑定1台小米路由器
Xiaomi_AAAA(小米路由器3增强版)root密码 xxxxxxxx下载工具包
工具包使用方法:小米路由器需升级到开发版0.5.28及以上,小米路由器mini需升级到开发版0.3.84及以上,小米路由器3即将支持。注意:稳定版不支持。
请将下载的工具包bin文件复制到U盘(FAT/FAT32格式)的根目录下,保证文件名为miwifi_ssh.bin;
断开小米路由器的电源,将U盘插入USB接口;
按住reset按钮之后重新接入电源,指示灯变为黄色闪烁状态即可松开reset键;
等待3-5秒后安装完成之后,小米路由器会自动重启,之后您就可以尽情折腾啦 :)

Google Translate of Website
Has been bundled with a millet router
Xiaomi_AAAA (millet router 3 enhanced version) root password xxxxxx download kit
Toolkit to use: millet router to be upgraded to the development version of 0.5.28 and above, millet router mini to be upgraded to the development version of 0.3.84 and above, millet router 3 is about to support. Note: Steady version does not support.
Please download the toolkit bin file to U disk (FAT / FAT32 format) root directory, to ensure that the file name miwifi_ssh.bin;
Disconnect the power supply millet router, the U disk into the USB interface;
Hold down the reset button and then re-access the power, the indicator light to yellow flashing state can release the reset button;
Wait 3-5 seconds after the installation is complete, millet router will automatically restart, then you can enjoy tossing :)

Saturday, September 30, 2017

Step-by-Step: OpenWRT/LEDE Base Installation for Xiaomi MiWiFi 3GR

The Xiaomi 3G router has a low price and spacious ROM (128MB) and RAM (256MB) for easily supporting most of the packages and loads a person would put on a OpenWRT/LEDE installation.  Thanks to some recent hard work by the LEDE community it’s fairly straight-forward to replace the Stock OEM firmware with LEDE.

NOTE: Development for the Xiaomi 3G is currently considered in BETA and should only be done by people who are content to support themselves and deal with bugs.  Having said that, I've found the most recent ROMs (March 2018) to be good enough for day-to-day use.

PREREQUISITES

A. A computer with a web browser for downloading the files, registering a Xiaomi account, and capable of running SSH.
B. The OpenWRT Installation Files from | downloads.openwrt.org
C. A Xiaomi Account for registering the router | https://account.xiaomi.com/pass/register
D.  The Developer edition of the wifi ROM from Xiaomi | http://www.miwifi.com/miwifi_download.html
  • Click the ROM graphic, scroll down to find “ROM for R3G 开发版”
E. A mobile device with Xiaomi’s router app installed | Google Play Link | Xiaomi APK
F. The customized SSH BIN file from Xiaomi.  This file can only be downloaded after registering the router with the Router app on your phone or tablet and it’s unique to each router since the ROOT password is apparently baked into it | Xiaomi SSH Site
G. A physical Ethernet connection to the router’s LAN ports (white colored).  Note: You can do most of the process on Wifi, but not all of it, so I recommend starting with Ethernet to simplify the process.
H. A USB drive formatted to FAT32 for installing the SSH BIN and LEDE BIN files to the router.

INSTRUCTIONS

1. Unbox the router (if it’s new), connect the WAN uplink (blue port) to the Internet, power it on, connect your computer to one of it’s ethernet ports with a computer (white port), open a browser and go to http://192.168.31.1, follow the onscreen router setup wizard (all in Chinese, but just use the same password for Admin and Wifi and you’ll be fine).
2. Download the "Developer" ROM from Xiaomi, if you haven’t already (see pre-reqs).
3. Manually flash the Developer ROM through the web app console.  Select the 3rd tab option, select the last menu item, and click the first command button to upload the file, click the right-hand button to confirm the installation of the new ROM. (It’s all in Chinese, so I’m trying to be helpful here, not condecending :-)
4. Install the Mi Wifi app on a mobile device
5. Connect your mobile device to the Wifi router's network
6. Sign into the app with your "Mi" account (or create one and then sign in, no personal information is needed other than an email account).
7. Sign into the Wifi Router through the app using the admin password you set during setup.  The router should now be registered to your Xiaomi account, our “Bound” as Google Translate says.
8. Download the the SSH BIN patch file at https://d.miwifi.com/rom/ssh. It's supposed to be custom for your router, so I'm imagining it's because the BIN files needs your router's root password baked in.
<insert screenshot>
9. While you're at this site, also copy down the "root" password from the page; you’ll need it for SSH later.
<insert screenshot>
10. Copy the miwifi_ssh.bin file from your computer to a USB drive formatted with FAT32.
11. Insert this USB drive into the USB port on the back of the Xiaomi router
12. Unplug the router's power cable.
13. Use a tool (like a straightened paperclip) to press down the reset button on the back of the router and hold it in.  While keeping the button pressed down, reconnect the power cable...not a task for the manually challenged. The yellow status light will come on the front of the router. After about 10 seconds, the yellow status light will begin to blink indicating that the router is now installing the SSH BIN file.  Now that the yellow light is flashing, you can finally release the reset button.

14. After the SSH file is installed, the router will reboot and the yellow light will become steady again during the boot process.  After the router is done booting, the status LED will turn a steady "blue" color.
15. Sign into the router using a ssh command from your computer and enter the enter the root password from the Xiaomi website
e.g. ssh root@192.168.31.1
<insert screenshot>
You're in! Enjoy your new super powers wisely
16. Download the following LEDE BIN files from the SNAPSHOT tree | Download Page
lede-ramips-mt7621-mir3g-squashfs-kernel1.bin
lede-ramips-mt7621-mir3g-squashfs-rootfs0.bin
17. Copy these two files to your USB drive and insert the USB drive back into the router.
18.  Within the SSH console, use these commands to flash the files:

cd /extdisks/sda1 (can be different if you remove and reinsert the usb stick)
mtd write lede-ramips-mt7621-mir3g-squashfs-kernel1.bin kernel1
mtd write lede-ramips-mt7621-mir3g-squashfs-rootfs0.bin rootfs0
nvram set flag_last_success=1
nvram commit
reboot

     The router will reboot, and congratulations! You're now running LEDE SNAPSHOT. You'll need to SSH back in and install uHTTPd and Luci to get into the web app again (No web console out of the box with SNAPSHOT) and you'll also need to reconfigure Wifi since it's disabled by default in the Snapshot images.  Here's some tips to install those core apps if you're not familiar:

ssh root@192.168.1.1
opkg update
opkg install uhttpd luci luci-app-uhttpd


UPDATING THE ROUTER FIRMWARE


Flash the TAR file from the Snapshot Repository (instead of a BIN file)
  • mir3g-squashfs-sysupgrade.tar

REFERENCES
Xiaomi SSH Website After Registering Your Device in the App

小米ID:0000000000
已绑定1台小米路由器
Xiaomi_AAAA(小米路由器3增强版)root密码 xxxxxxxx下载工具包
工具包使用方法:小米路由器需升级到开发版0.5.28及以上,小米路由器mini需升级到开发版0.3.84及以上,小米路由器3即将支持。注意:稳定版不支持。

请将下载的工具包bin文件复制到U盘(FAT/FAT32格式)的根目录下,保证文件名为miwifi_ssh.bin;
断开小米路由器的电源,将U盘插入USB接口;
按住reset按钮之后重新接入电源,指示灯变为黄色闪烁状态即可松开reset键;
等待3-5秒后安装完成之后,小米路由器会自动重启,之后您就可以尽情折腾啦 :)

Google Translate of Website

Has been bundled with a millet router
Xiaomi_AAAA (millet router 3 enhanced version) root password xxxxxx download kit
Toolkit to use: millet router to be upgraded to the development version of 0.5.28 and above, millet router mini to be upgraded to the development version of 0.3.84 and above, millet router 3 is about to support. Note: Steady version does not support.

Please download the toolkit bin file to U disk (FAT / FAT32 format) root directory, to ensure that the file name miwifi_ssh.bin;
Disconnect the power supply millet router, the U disk into the USB interface;
Hold down the reset button and then re-access the power, the indicator light to yellow flashing state can release the reset button;
Wait 3-5 seconds after the installation is complete, millet router will automatically restart, then you can enjoy tossing :)

LEDE FORUM COMMENT WITH BEST INSTRUCTIONS
https://forum.lede-project.org/t/xiaomi-wifi-router-3g/5377/57

This is how I got LEDE installed. Some of the steps can be done differently. I used this for inspiration https://www.youtube.com/watch?v=CSHNyo5QxaQ40
Unbox router
Connect to the router using WiFi
Goto http://192.168.31.11
Go through the wizard to set passwords for the router + wifi
Reconnect to the router using WiFi
Goto http://192.168.31.11
Logon and find the page where you can upgrade the firmware look for a big yellow dot with an “i” inside. You will see the version number of the router and there is a button below where you can browse for a file. Flash miwifi_r3g_firmware_c2175_2.25.122.bin (developer firmware) and wait a few minutes.
Download https://play.google.com/store/apps/details?id=com.xiaomi.router13 to your phone/tablet (there is also an iOS app)
Open “Mi Wi-Fi” app (and sign-up) and sign-in to your account. Router will be detected and added to your account (assuming you are connected to the WiFi on the router and the routers WAN port is connected to Internet).
On a PC, visit http://d.miwifi.com/rom/ssh18 and sign-in to you account. You will get to a page that should display your router, the root password and a download button. Hit the button to get miwifi_ssh.bin
Format USB drive using FAT32 and copy miwifi_ssh.bin, lede-ramips-mt7621-mir3g-squashfs-kernel1.bin and lede-ramips-mt7621-mir3g-squashfs-rootfs0.bin to the USB drive
Cut the power the router, put the USB drive in the router, press and hold “reset” button (with a paper-clip), power on the router (while holding reset). When the router starts flashing yellow release the reset button. Wait until router has rebooted and you should (finally…) have SSH access.
Login to the router using SSH using the “root” as username and the (root) “password” from http://d.miwifi.com/rom/ssh18
In SSH console
cd /extdisks/sda1 (can be different if you remove and reinsert the usb stick)
mtd write lede-ramips-mt7621-mir3g-squashfs-kernel1.bin kernel1
mtd write lede-ramips-mt7621-mir3g-squashfs-rootfs0.bin rootfs0
nvram set flag_last_success=1
nvram commit
reboot
LEDE should be installed and available at 192.168.1.1 (with WiFi disabled I assume)
Upgrading to a newer snapshot can be done using the regular methods (from the command-line using sysupgrade or through LuCI) using lede-ramips-mt7621-mir3g-squashfs-sysupgrade.tar
Thanks @dissent1 for adding the router to LEDE. Both WiFi radios seems to work (2.4Ghz on 20Mhz, 5Ghz on 80MHz) and I have also tested USB3 port with success. I have not tested 40MHz for 2.4Ghz as it does not make sense for me (very crowded WiFi). 5Ghz radio does not seem to like DFS channels (I get “DFS start_dfs_cac() failed, -1” in the log). The channels seems to work nicely when disabling DFS (by removing the requirement from regdb.txt for the selected country before building firmware) so this is likely “just” a DFS issue.
I can’t say anything about stability yet. I’ll probably try to replace my TP-Link Archer C5 with the Xiaomi router within the next week and then I will have to see how well it performs and how stable it is.

UPDATED on March 3, 2018 to include links to the OpenWRT repositories since the two projects have merged.

Wednesday, December 14, 2016

Step-by-step: Install OpenWRT on the Xiaomi Wifi Mini router from a Windows Computer (2016 edition)

UPDATE: These instructions no longer work because Xiaomi has patched the firmware bug that allowed us to bypass the security and unlock the ROM.  Now a user must install the "Developer Edition" of the official Xiaomi firmware, register the router with a Xiaomi account, and then unlock the router.  These instructions are posted in another post [LINK].

I found the instructions to install OpenWRT on the Xiaomi Wifi Mini to be difficult to follow [openwrt device page], so I've summarized the instructions below.  Please note that this is for OpenWRT 15.05.1 on the Xiaomi Mini Wifi (小米 路由器MINI )

NOTE: It appears that the Xiaomi Mini has been discontinued since it is no longer listed as an active product on Xiaomi's store. They have replaced it with two other models which do not have active OpenWRT development - however they are still available from 3rd party sellers on tmall.com

Unlock the Router & Enable Telnet

1. Connect the router to power.
2. Connect an internet patch cable to the WAN Uplink port (blue colored).
3. Connect a Windows computer to one of the Ethernet switch ports on the router (white colored).
4. Launch a web browser and connect to the administrator console by going to the following address:
http://192.168.31.1, If you cannot reach the administrator console:
     * Check the IP address on your computer and verify the it starts with 192.168.31
     * Verify that you have any VPN software turned OFF
     * Verify that the Proxy settings are disabled in “Internet Options”
5. Follow the setup wizard and configure the router.
     * Note: It will ask you to set the wifi and the administrator password. Set it to 1234567890
     * Note: All settings made during this process will be erased later, so don’t spend time making it nice...
After you complete the setup wizard, the router will reboot.
6. Connect to the web administrator console again and sign-in to the router and copy the value of the stok URL parameter from the address (for example: "9c2428de4d17e2db7e5a6a337e6f57a3")

7. Replace the <STOK> placeholder below with the value from the new router and copy this address into the URL in your browser. (Note: This will start the telnetd service on the router):
http://192.168.31.1/cgi-bin/luci/;stok=<STOK>/api/xqnetwork/set_wifi_ap?ssid=whatever&encryption=NONE&enctype=NONE&channel=1%3B%2Fusr%2Fsbin%2Ftelnetd
After about 30 seconds a successful command will display the following error code:
Chinese: {"msg":"未能連線到指定Wi-Fi(Probe timeout)","code":1616}
or English: {"msg":"Couldn't connect to this network(Probe timeout)","code":1616}
8. Replace the <STOK> placeholder below with the value from the new router and copy this address into the URL in your browser. (Note: This will change the root password from 1234567890 to 123456abc on the router):
http://192.168.31.1/cgi-bin/luci/;stok=<STOK>/api/xqsystem/set_name_password?oldPwd=1234567890&newPwd=123456abc
After about 5 seconds a successful command will display the following error code:
{"code":0}

Install OpenWRT on the Router from a Windows Computer

1. Run putty (download it if you do not have it on your computer) and start a Telnet connection to the router with the following two options:
  • Host Name (or IP address):    192.168.31.1
  • Connection type:                     Telnet


2. Sign into the console using the following account information
  • XiaoQiang login:    root
  • Password:         123456abc

3. Get the latest firmware from OpenWRT using these Telnet shell commands:
  • # cd /tmp
  • wget http://downloads.openwrt.org/chaos_calmer/15.05.1/ramips/mt7620/openwrt-15.05.1-ramips-mt7620-xiaomi-miwifi-mini-squashfs-sysupgrade.bin

4. Check the MTD layout on the router to make sure you don't damage it:
  • cat /proc/mtd

If you find a line "OS1" go ahead with flashing:
mtd -r write openwrt-15.05.1-ramips-mt7620-xiaomi-miwifi-mini-squashfs-sysupgrade.bin OS1
     * Note: for LEDE, replace the file name with the correct one, like this: mtd -r write lede-17.01.2-ramips-mt7620-miwifi-mini-squashfs-sysupgrade.bin OS1
After flashing is complete, the router will reboot. Wait about 10 minutes to ensure that the firmware is installed properly and then power off the router and power it back on my disconnecting the power.

Please note that the OpenWrt binary defaults to the red color of the led instead of the orange/blue during and after finishing the boot that Xiaomi uses.

Comments on how OpenWRT runs on the Xiaomi Wifi Mini Router

  • There is LOTS of memory on the Xiaomi - it is a luxurious amount of space to install packages on and run them in memory.
  • The ROM is stable.
  • I have tested several VPN/proxy packages's on it like OpenVPN, stunnel, and shadowsocks; they all run well on OpenWRT and this hardware.
  • The Wifi is not stable. From extensive testing I assume that Xiaomi is running some custom drivers or doing some software tricks to make the wifi work properly (the wifi works perfectly on the stock Xiaomi ROM).  Suggestion - Use the Xiaomi as a router and attach another Wifi router to it for WAP functions.
  • The wifi is available for international shipping from several 3rd party sellers on Aliexpress (in China they retail for 130rmb - about US$20) [Search Results]