Adding OpenWrt support for TP-Link Archer MR200 V4?

it seems you can build a image flashable from tftp

I cannot find mr200v4 anywhere even when choosing target profile under MT76x2

make sure you use mr200v4 branch
git clone -b mr200v4 https://github.com/Lochnair/openwrt.git
then browse to mt76x8

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
  β”‚ β”‚                             Target System (MediaTek Ralink MIPS)  --->                                                  β”‚ β”‚
  β”‚ β”‚                             Subtarget (MT76x8 based boards)  --->                                                       β”‚ β”‚
  β”‚ β”‚                             Target Profile (TP-Link ArcherMR200 v4)  --->      

Can you please please upload a working tftp-recovery.bin so I can flash?

Check my answer 3 posts above

What I meant is a ready built image :frowning:

i don't have v4 and can't help further

Is there any updates on this? Can I flash v1 firmware on v4?

OpenWrt Firmware Selector

You could, if you're willing to risk a brick.

Ahh... So nobody has done it before huh?

Cheers.

It's a different SoC (MT7620 vs MT7628 IIRC), so doubt that'll work. And the modem works differently (which is why I gave up on it, see above).

1 Like

Thx bro!!!

Hi @Lochnair

I have "borrowed" your fork of MR200v4 and compiled a image.
But I have some problems with the QMI communication to the modem.
How far did you get in your investigation? Where you able to have a stable QMI-communication with the modem?
I can run one or two commands and then it hangs.
Did you have any serial interface to you modem?

This is all I have in dmesg:

[   12.076077] qmi_wwan 1-1:1.4: cdc-wdm0: USB WDM device
[   12.083532] qmi_wwan 1-1:1.4 wwan0: register 'qmi_wwan' at usb-101c0000.ehci-1, WWAN/QMI device, 0e:e8:b7:e3:c5:7b

@mrhaav
I don't remember exactly how much I was able to solve back then.
I do remember having that issue with QMI hanging, but I can't really say if that was fixed with initializing the Android part, or how that worked.

As for serial, no not as far as I know. The serial access for the modem if there is one would be on the Android part of the router. So you might be able to hook up something with adb.
I wasn't all that familiar with how modems worked at the time, so I didn't really try to get serial access to it, since I thought I'd get by fine with QMI.

It'd be awesome if you managed to get it working properly somehow. I do still have mine laying around collecting dust at the family vacation home, so I could potentially help test things, but honestly I still believe this thing really isn't worth the effort if you can afford getting something more OpenWrt friendly.

I have now compiled a 19.07.8 image, based on @Lochnair Β΄s fork (with minor changes), and I have the modem working. :slight_smile:

The modem just support a limited amount of qmi command. So I have modified the qmi.sh script. For the moment I have no error checking and I had to remove all PIN code checking. I have not verified the IPv6 function. My cellular provider are not using IPv6 and I donΒ΄t understand how to configure it with uqmi. Maybe I need to use qmicli.

I needed set the Modem init timeout = 20 and add uci set network.wwan.dhcp='0'.
I think the "noDHCP" option is new in 21.02.0, or?

My modified /lib/netifd/proto/qmi.sh file:

#!/bin/sh

[ -n "$INCLUDE_ONLY" ] || {
        . /lib/functions.sh
        . ../netifd-proto.sh
        init_proto "$@"
}

proto_qmi_init_config() {
        available=1
        no_device=1
        proto_config_add_string "device:device"
        proto_config_add_string apn
        proto_config_add_string auth
        proto_config_add_string username
        proto_config_add_string password
        proto_config_add_string pincode
        proto_config_add_int delay
        proto_config_add_string modes
        proto_config_add_string pdptype
        proto_config_add_int profile
        proto_config_add_boolean dhcp
        proto_config_add_boolean dhcpv6
        proto_config_add_boolean autoconnect
        proto_config_add_int plmn
        proto_config_add_int timeout
        proto_config_add_int mtu
        proto_config_add_defaults
}

proto_qmi_setup() {
        local interface="$1"
        local dataformat connstat
        local device apn auth username password pincode delay modes pdptype
        local profile dhcp dhcpv6 autoconnect plmn timeout mtu $PROTO_DEFAULT_OPTIONS
        local ip4table ip6table
        local cid_4 pdh_4 cid_6 pdh_6
        local ip_6 ip_prefix_length gateway_6 dns1_6 dns2_6

        json_get_vars device apn auth username password pincode delay modes
        json_get_vars pdptype profile dhcp dhcpv6 autoconnect plmn ip4table
        json_get_vars ip6table timeout mtu $PROTO_DEFAULT_OPTIONS

        [ "$timeout" = "" ] && timeout="10"

        [ "$metric" = "" ] && metric="0"

        [ -n "$ctl_device" ] && device=$ctl_device

        [ -n "$device" ] || {
                echo "No control device specified"
                proto_notify_error "$interface" NO_DEVICE
                proto_set_available "$interface" 0
                return 1
        }

        [ -n "$delay" ] && sleep "$delay"

        device="$(readlink -f $device)"
        [ -c "$device" ] || {
                echo "The specified control device does not exist"
                proto_notify_error "$interface" NO_DEVICE
                proto_set_available "$interface" 0
                return 1
        }

        devname="$(basename "$device")"
        devpath="$(readlink -f /sys/class/usbmisc/$devname/device/)"
        ifname="$( ls "$devpath"/net )"
        [ -n "$ifname" ] || {
                echo "The interface could not be found."
                proto_notify_error "$interface" NO_IFACE
                proto_set_available "$interface" 0
                return 1
        }

        [ -n "$mtu" ] && {
                echo "Setting MTU to $mtu"
                /sbin/ip link set dev $ifname mtu $mtu
        }

        local uninitialized_timeout=0


        # Set driver to raw_ip
        raw_ip=$(cat /sys/class/net/$ifname/qmi/raw_ip)
        [ "$raw_ip" = "N" ] && {
                echo Setting driver to raw_ip
                echo "Y" > /sys/class/net/$ifname/qmi/raw_ip
        }


        echo Resetting modem
        uqmi -d "$device" --set-autoconnect disabled
        sleep 1
        echo Initiate flight mode
        uqmi -s -d "$device" --set-device-operating-mode factory_test
        sleep 2
        json_load "$(uqmi -s -d "$device" --get-serving-system)"
        json_get_var registration registration
        while [ $registration = registered ]
        do
                sleep 2
                json_load "$(uqmi -s -d "$device" --get-serving-system)"
                json_get_var registration registration
        done
        echo Flight mode on
        echo Flight mode off
        uqmi -s -d "$device" --set-device-operating-mode online
        sleep 1
        uqmi -s -d "$device" --network-register
        sleep 1
        json_load "$(uqmi -s -d "$device" --get-serving-system)"
        json_get_var registration registration
        echo Waiting for registration
        while [ $registration != registered ]
        do
                sleep 1
                json_load "$(uqmi -s -d "$device" --get-serving-system)"
                json_get_var registration registration
        done

        json_get_var operator plmn_description
        echo Registered to $operator

        cid_4=$(uqmi -d "$device" --get-client-id wds)
        sleep 1

        pdh_4=$(uqmi -s -d "$device" --set-client-id wds,"$cid_4" \
                --start-network \
                ${apn:+--apn $apn} \
                ${auth:+--auth-type $auth} \
                ${username:+--username $username} \
                ${password:+--password $password})



# Start interface
        echo "Setting up $ifname"
        proto_init_update "$ifname" 1
        proto_set_keep 1
        proto_add_data
        [ -n "$pdh_4" ] && {
                json_add_string "cid_4" "$cid_4"
                json_add_string "pdh_4" "$pdh_4"
        }
        [ -n "$pdh_6" ] && {
                json_add_string "cid_6" "$cid_6"
                json_add_string "pdh_6" "$pdh_6"
        }
        proto_close_data
        proto_send_update "$interface"

        local zone="$(fw3 -q network "$interface" 2>/dev/null)"

        [ -n "$pdh_6" ] && {
                if [ -z "$dhcpv6" -o "$dhcpv6" = 0 ]; then
                        json_load "$(uqmi -s -d $device --set-client-id wds,$cid_6 --get-current-settings)"
                        json_select ipv6
                        json_get_var ip_6 ip
                        json_get_var gateway_6 gateway
                        json_get_var dns1_6 dns1
                        json_get_var dns2_6 dns2
                        json_get_var ip_prefix_length ip-prefix-length

                        proto_init_update "$ifname" 1
                        proto_set_keep 1
                        proto_add_ipv6_address "$ip_6" "128"
                        proto_add_ipv6_prefix "${ip_6}/${ip_prefix_length}"
                        proto_add_ipv6_route "$gateway_6" "128"
                        [ "$defaultroute" = 0 ] || proto_add_ipv6_route "::0" 0 "$gateway_6" "" "" "${ip_6}/${ip_prefix_length}"
                        [ "$peerdns" = 0 ] || {
                                proto_add_dns_server "$dns1_6"
                                proto_add_dns_server "$dns2_6"
                        }
                        [ -n "$zone" ] && {
                                proto_add_data
                                json_add_string zone "$zone"
                                proto_close_data
                        }
                        proto_send_update "$interface"
                else
                        json_init
                        json_add_string name "${interface}_6"
                        json_add_string ifname "@$interface"
                        json_add_string proto "dhcpv6"
                        [ -n "$ip6table" ] && json_add_string ip6table "$ip6table"
                        proto_add_dynamic_defaults
                        # RFC 7278: Extend an IPv6 /64 Prefix to LAN
                        json_add_string extendprefix 1
                        [ -n "$zone" ] && json_add_string zone "$zone"
                        json_close_object
                        ubus call network add_dynamic "$(json_dump)"
                fi
        }

        [ -n "$pdh_4" ] && {
                if [ "$dhcp" = 0 ]; then
                        json_load "$(uqmi -s -d $device --set-client-id wds,$cid_4 --get-current-settings)"
                        json_select ipv4
                        json_get_var ip_4 ip
                        json_get_var gateway_4 gateway
                        json_get_var dns1_4 dns1
                        json_get_var dns2_4 dns2
                        json_get_var subnet_4 subnet

                        proto_init_update "$ifname" 1
                        proto_set_keep 1
                        proto_add_ipv4_address "$ip_4" "$subnet_4"
                        proto_add_ipv4_route "$gateway_4" "128"
                        [ "$defaultroute" = 0 ] || proto_add_ipv4_route "0.0.0.0" 0 "$gateway_4"
                        [ "$peerdns" = 0 ] || {
                                proto_add_dns_server "$dns1_4"
                                proto_add_dns_server "$dns2_4"
                        }
                        [ -n "$zone" ] && {
                                proto_add_data
                                json_add_string zone "$zone"
                                proto_close_data
                        }
                        proto_send_update "$interface"
                else
                        json_init
                        json_add_string name "${interface}_4"
                        json_add_string ifname "@$interface"
                        json_add_string proto "dhcp"
                        [ -n "$ip4table" ] && json_add_string ip4table "$ip4table"
                        proto_add_dynamic_defaults
                        [ -n "$zone" ] && json_add_string zone "$zone"
                        json_close_object
                        ubus call network add_dynamic "$(json_dump)"
                fi
        }
}

qmi_wds_stop() {
        local cid="$1"
        local pdh="$2"

        [ -n "$cid" ] || return

        uqmi -s -d "$device" --set-client-id wds,"$cid" \
                --stop-network 0xffffffff \
                --autoconnect > /dev/null 2>&1

        [ -n "$pdh" ] && {
                uqmi -s -d "$device" --set-client-id wds,"$cid" \
                        --stop-network "$pdh" > /dev/null 2>&1
        }

        uqmi -s -d "$device" --set-client-id wds,"$cid" \
                --release-client-id wds > /dev/null 2>&1
}

proto_qmi_teardown() {
        local interface="$1"

        local device cid_4 pdh_4 cid_6 pdh_6
        json_get_vars device

        [ -n "$ctl_device" ] && device=$ctl_device

        echo "Stopping network $interface"

        json_load "$(ubus call network.interface.$interface status)"
        json_select data
        json_get_vars cid_4 pdh_4 cid_6 pdh_6

        qmi_wds_stop "$cid_4" "$pdh_4"
        qmi_wds_stop "$cid_6" "$pdh_6"

        proto_init_update "*" 0
        proto_send_update "$interface"
}

[ -n "$INCLUDE_ONLY" ] || {
        add_protocol qmi
}

Maybe this will work for other routers with the same modem.
cat /sys/kernel/debug/usb/devices

T:  Bus=01 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#=  2 Spd=480  MxCh= 0
D:  Ver= 2.00 Cls=00(>ifc ) Sub=00 Prot=00 MxPS=64 #Cfgs=  1
P:  Vendor=05c6 ProdID=9025 Rev= 3.18
S:  Manufacturer=Android
S:  Product=Android
S:  SerialNumber=0123456789ABCDEF
C:* #Ifs= 6 Cfg#= 1 Atr=a0 MxPwr=500mA
I:* If#= 0 Alt= 0 #EPs= 2 Cls=ff(vend.) Sub=ff Prot=ff Driver=(none)
E:  Ad=81(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms
E:  Ad=01(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms
I:* If#= 1 Alt= 0 #EPs= 2 Cls=ff(vend.) Sub=42 Prot=01 Driver=(none)
E:  Ad=02(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms
E:  Ad=82(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms
I:* If#= 2 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=00 Prot=00 Driver=(none)
E:  Ad=84(I) Atr=03(Int.) MxPS=  10 Ivl=32ms
E:  Ad=83(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms
E:  Ad=03(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms
I:* If#= 3 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=00 Prot=00 Driver=(none)
E:  Ad=86(I) Atr=03(Int.) MxPS=  10 Ivl=32ms
E:  Ad=85(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms
E:  Ad=04(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms
I:* If#= 4 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=ff Prot=ff Driver=qmi_wwan
E:  Ad=88(I) Atr=03(Int.) MxPS=   8 Ivl=32ms
E:  Ad=87(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms
E:  Ad=05(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms
I:* If#= 5 Alt= 0 #EPs= 2 Cls=08(stor.) Sub=06 Prot=50 Driver=usb-storage
E:  Ad=89(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms
E:  Ad=06(O) Atr=02(Bulk) MxPS= 512 Ivl=125us

I mistakenly tried following the guide for installing OpenWrt on the Archer MR200

which was specifically for v1 and it turns out I have v4, so if anyone has an image I coud try, can you tell me where to get it and how to install it?

Glad to hear someone got this thing to work in the end : )
I think by the time I got to that part I'd run out of patience :sweat_smile:

Did you try to use modemmanager with this? That's what I'm using now at our vacation home setup.
Not sure I knew about it when I was looking at this, so might be worth a try.

I wrote the instructions for flashing this thing over here: https://github.com/Lochnair/openwrt-mr200v4#installation, if you don't have them. Didn't bother filling out a wiki page until I had something that worked properly.

I think the stock firmware recovery is the same as for the MR200v1, but it's mentioned there as well if you need it.

Applied the qmi.sh changes @mrhaav did in the repository, so if he's not around I could probably throw together an image for you if you need it

1 Like

Not really sure about what you mean by modemmanager...

A link would be useful.

This stuff: https://openwrt.org/docs/guide-user/network/wan/wwan/modemmanager
It's a much bigger package than the script based variants otherwise used in OpenWrt (the binary is 1.4MiB on mine), but since it's used on standard distros as well, it could be that they've covered more edge cases like this weird modem already.