diff options
author | Loic Poulain <loic.poulain@linaro.org> | 2020-10-14 10:21:33 -0400 |
---|---|---|
committer | Loic Poulain <loic.poulain@linaro.org> | 2020-10-14 10:21:33 -0400 |
commit | e6686087f368a44f39bb2219d570baad231f8dd8 (patch) | |
tree | d850e1c0ab74e8c78f1db06b4b00077e01e958da |
Add legacy connection script (via wmicli and MHI UCI)
-rwxr-xr-x | mhi-qmi-connect-legacy | 216 |
1 files changed, 216 insertions, 0 deletions
diff --git a/mhi-qmi-connect-legacy b/mhi-qmi-connect-legacy new file mode 100755 index 0000000..a20b699 --- /dev/null +++ b/mhi-qmi-connect-legacy @@ -0,0 +1,216 @@ +#!/bin/bash + +trap interrupt_cb INT + +qmidev="" +iface_id=4 +mux_id=1 +ep=pcie +wds_options="" +mtu=8192 +apn="" +res="" +wwan_iface="mhi_hwip0" +rmnet_iface="rmnet_data${mux_id}" + +usage() +{ + echo "Usage:" + echo " $0 <APN_NAME> [SIM_PIN]" +} + +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=16,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>&1) + 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 /dev/mhi_0000\:04\:00.0_QMI --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 (( $# < 1 )); then + usage + exit 1 +fi +apn=$1 + +qmi_device_find +if (( $# > 1 )); then + pin=$2 + qmi_uim_verify_pin +fi +qmi_uim_sim_on +qmi_nas_wait_carrier +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 |