diff options
author | Loic Poulain <loic.poulain@linaro.org> | 2020-10-28 19:09:19 +0100 |
---|---|---|
committer | Loic Poulain <loic.poulain@linaro.org> | 2020-10-28 19:09:19 +0100 |
commit | 2fd43fcbc54049684020f1549bba693dc6417471 (patch) | |
tree | 3899fae10d76bce99de50f15e8565db4fe6de491 | |
parent | eaad933538bfc05e4fab4f38ed12641c6e26fed3 (diff) |
Adjust MTU to maximum one supported by rmnet
Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
-rwxr-xr-x | mhi-qmi-connect-loopback.sh | 203 | ||||
-rwxr-xr-x | mhi-qmi-connect.sh (renamed from mhi-qmi-connect-legacy) | 4 |
2 files changed, 205 insertions, 2 deletions
diff --git a/mhi-qmi-connect-loopback.sh b/mhi-qmi-connect-loopback.sh new file mode 100755 index 0000000..022ded8 --- /dev/null +++ b/mhi-qmi-connect-loopback.sh @@ -0,0 +1,203 @@ +#!/bin/bash + +trap interrupt_cb INT + +qmidev="" +iface_id=4 +mux_id=1 +ep=pcie +wds_options="" +mtu=16384 +apn="test" +res="" +wwan_iface="mhi_hwip0" +rmnet_iface="rmnet_data${mux_id}" + +qmi_device_find() +{ + qmidev=$(ls /dev/mhi_*QMI | head -1) + if (( $? != 0 )); then + echo "** ERROR: QMI UCI device not found" + exit -1 + fi + echo "** QMI device found: ${qmidev}" +} + +qmi_wda_set_data_format() +{ + res=$(qmicli -d ${qmidev} --wda-set-data-format ep-type=${ep},ep-iface-number=${iface_id},link-layer-protocol=raw-ip,ul-protocol=qmap,dl-protocol=qmap,dl-max-datagrams=32,dl-datagram-max-size=${mtu} 2>&1) + if (( $? != 0 )); then + echo "** ERROR: Unable to set data format" + echo "------" + echo $res + echo "------" + exit -1 + fi +} + +qmi_wds_get_cid() +{ + res=$(qmicli -d ${qmidev} --wds-noop --client-no-release-cid 2>&1) + if (( $? != 0 )); then + echo "** ERROR: unable to get WDS CID" + echo "------" + echo $res + echo "------" + exit 1 + fi + wds_cid=`echo "$res" | sed -n "s/.*CID.*'\(.*\)'.*/\1/p"` + echo "** Allocated WDS CID $wds_cid" + wds_options="--client-cid=${wds_cid} --client-no-release-cid" +} + +qmi_wds_release_cid() +{ + res=$(qmicli -d ${qmidev} --wds-noop --client-cid=${wds_cid} 2>&1) + echo "** Released WDS CID ${wds_cid}" +} + +qmi_wds_reset() +{ + res=$(qmicli -d ${qmidev} --wds-reset ${wds_options} 2>&1) + if (( $? != 0 )); then + echo "** ERROR: unable to reset WDS" + echo "------" + echo $res + echo "------" + qmi_wds_release_cid + exit 1 + fi +} + +qmi_wds_bind_mux_data_port() +{ + res=$(qmicli -d ${qmidev} --wds-bind-mux-data-port ep-type=${ep},ep-iface-number=${iface_id},mux-id=${mux_id} ${wds_options} 2>&1) + if (( $? != 0 )); then + echo "** ERROR: unable to bind mux data port" + echo "------" + echo $res + echo "------" + qmi_wds_release_cid + exit 1 + fi +} + +qmi_wds_start_network() +{ + echo -n "** Connecting to APN ${apn}... " + res=$(qmicli -d ${qmidev} --wds-start-network="ip-type=4,apn=${apn}" ${wds_options} 2>&1) + if (( $? != 0 )); then + echo "ERROR Unable to connect to ${apn}" + echo "------" + echo $res + echo "------" + qmi_wds_release_cid + exit 1 + fi + echo "Connected!" +} + +net_ipaddr="not-found" +net_dns="not-found" +net_mtu="not-found" + +qmi_wds_get_settings() +{ + res=$(qmicli -d ${qmidev} --wds-get-current-settings ${wds_options} 2> /dev/null) + if (( $? != 0 )); then + echo "**ERROR retrieving settings" + echo "------" + echo $res + echo "------" + qmi_wds_release_cid + exit 1 + fi + net_ipaddr=$(echo $res | sed -n "s/.*IPv4 address: \(.*\) '.*/\1/p" | cut -d" " -f1) + net_dns=$(echo $res | sed -n "s/.*DNS: \(.*\) '.*/\1/p" | cut -d" " -f1) + net_mtu=$(echo $res | sed -n "s/.*MTU: \(.*\) '.*/\1/p" | cut -d" " -f1) + echo "** IPv4 => $net_ipaddr" + echo "** DNS1 => $net_dns" + echo "** MTU => $net_mtu" +} + +qmi_uim_sim_on() +{ + res=$(qmicli -d ${qmidev} --dms-set-operating-mode=online 2>&1) + res=$(qmicli -d ${qmidev} --uim-sim-power-on=1 2>&1) +} + +qmi_uim_verify_pin() +{ + echo -n "** Verifying UIM pin1... " + res=$(qmicli -d ${qmidev} --uim-verify-pin PIN1,1234 2>&1) + if (( $? != 0 )); then + echo "ERROR!" + echo "------" + echo $res + echo "------" + exit 1 + fi + echo "OK!" +} + +qmi_nas_wait_carrier() +{ + echo -n "** Waiting operator registration..." + while (true); do + sleep 1 + res=$(qmicli -d ${qmidev} --nas-get-serving-system 2>&1 | grep registered) + if [[ "$res" == *"'registered'"* ]]; then + echo " OK!" + break + fi + echo -n "." + done +} + +setup_rmnet() +{ + # set MTU + ip link set ${wwan_iface} mtu ${mtu} + # Create bridge + ip link add link ${wwan_iface} name ${rmnet_iface} type rmnet mux_id ${mux_id} + ip link set ${rmnet_iface} mtu ${mtu} + ip addr add ${net_ipaddr}/27 dev ${rmnet_iface} + ip link set ${wwan_iface} up + ip link set ${rmnet_iface} up + ip route del default + ip route add default via ${net_ipaddr} + echo "nameserver ${net_dns}" > /etc/resolv.conf +} + +release_rmnet() +{ + res=$(ip link set ${rmnet_iface} down 2>&1) + res=$(ip link set ${wwan_iface} down 2>&1) + res=$(ip link del ${rmnet_iface} 2>&1) + res=$(ip route del ${net_ipaddr} 2>&1) + echo "nameserver 8.8.8.8" > /etc/resolv.conf +} + +interrupt_cb() +{ + echo " => Interrupted" + qmi_wds_release_cid + release_rmnet + exit 0 +} + +if [ "$EUID" -ne 0 ]; then + echo "Please run as root" + exit +fi + +qmi_device_find +qmi_wda_set_data_format +qmi_wds_get_cid +qmi_wds_reset +qmi_wds_bind_mux_data_port +qmi_wds_start_network +qmi_wds_get_settings +setup_rmnet +echo "** Ready! (ctrl+c to stop wwan network)" +sleep infinity diff --git a/mhi-qmi-connect-legacy b/mhi-qmi-connect.sh index ec0680f..d9f2436 100755 --- a/mhi-qmi-connect-legacy +++ b/mhi-qmi-connect.sh @@ -7,7 +7,7 @@ iface_id=4 mux_id=1 ep=pcie wds_options="" -mtu=8192 +mtu=16384 apn="" res="" wwan_iface="mhi_hwip0" @@ -31,7 +31,7 @@ qmi_device_find() qmi_wda_set_data_format() { - res=$(qmicli -d ${qmidev} --wda-set-data-format ep-type=${ep},ep-iface-number=${iface_id},link-layer-protocol=raw-ip,ul-protocol=qmap,dl-protocol=qmap,dl-max-datagrams=16,dl-datagram-max-size=${mtu} 2>&1) + res=$(qmicli -d ${qmidev} --wda-set-data-format ep-type=${ep},ep-iface-number=${iface_id},link-layer-protocol=raw-ip,ul-protocol=qmap,dl-protocol=qmap,dl-max-datagrams=32,dl-datagram-max-size=${mtu} 2>&1) if (( $? != 0 )); then echo "** ERROR: Unable to set data format" echo "------" |