first commit

main
Ben 1 year ago
commit 60e53b706e

@ -0,0 +1,210 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=modeminfo
PKG_VERSION:=0.3.3
PKG_RELEASE:=3
PKG_MAINTAINER:=Konstantine Shevlakov <shevlakov@132lan.ru>
include $(INCLUDE_DIR)/package.mk
define Package/$(PKG_NAME)
PKGARCH:=all
SECTION:=net
CATEGORY:=Network
SUBMENU:=Telephony
DEPENDS:=+comgt
TITLE:=Signal information for 3G/LTE dongle
endef
define Package/$(PKG_NAME)-serial-simcom
PKGARCH:=all
SUBMENU:=Telephony
DEPENDS:=+modeminfo +kmod-usb-serial-option +atinout
TITLE:=SIMCOM serial addon for modeminfo
endef
define Package/$(PKG_NAME)-serial-huawei
PKGARCH:=all
SUBMENU:=Telephony
DEPENDS:=+modeminfo +kmod-usb-serial-option +atinout
TITLE:=HUAWEI serial addon for modeminfo
endef
define Package/$(PKG_NAME)-serial-quectel
PKGARCH:=all
SUBMENU:=Telephony
DEPENDS:=+modeminfo +kmod-usb-serial-option +atinout
TITLE:=QUECTEL serial addon for modeminfo
endef
define Package/$(PKG_NAME)-serial-fibocom
PKGARCH:=all
SUBMENU:=Telephony
DEPENDS:=+modeminfo +kmod-usb-serial-option +atinout
TITLE:=FIBOCOM NL668/678 serial addon for modeminfo
endef
define Package/$(PKG_NAME)-serial-telit
PKGARCH:=all
SUBMENU:=Telephony
DEPENDS:=+modeminfo +kmod-usb-serial-option +atinout
TITLE:= TELIT LN940/T77W678/HP4220 serial addon for modeminfo
endef
define Package/$(PKG_NAME)-serial-xmm
PKGARCH:=all
SUBMENU:=Telephony
DEPENDS:=+modeminfo +kmod-usb-acm +atinout
TITLE:= FIBOCOM L850/L860 Intel XMM chips serial addon for modeminfo
endef
define Package/$(PKG_NAME)-serial-sierra
PKGARCH:=all
SUBMENU:=Telephony
DEPENDS:=+modeminfo +kmod-usb-serial-qualcomm +atinout
TITLE:= Sierra Wireless EM7455 serial addon for modeminfo
endef
define Package/$(PKG_NAME)-serial-dell
PKGARCH:=all
SUBMENU:=Telephony
DEPENDS:=+modeminfo +kmod-usb-serial-option +atinout
TITLE:= Dell DW5821e serial addon for modeminfo
endef
define Package/$(PKG_NAME)-serial-gosun
PKGARCH:=all
SUBMENU:=Telephony
DEPENDS:=+modeminfo +kmod-usb-serial-option +atinout
TITLE:= Gosuncnwelink GM510 serial addon for modeminfo
endef
define Package/$(PKG_NAME)-serial-zte
PKGARCH:=all
SUBMENU:=Telephony
DEPENDS:=+modeminfo +kmod-usb-serial-option +atinout
TITLE:= ZTE MF823/MF823D serial addon for modeminfo
endef
define Package/$(PKG_NAME)-qmi
PKGARCH:=all
SUBMENU:=Telephony
DEPENDS:=+modeminfo +qmi-utils
TITLE:=QMI addon for modeminfo
endef
define Package/$(PKG_NAME)-telegram
PKGARCH:=all
SUBMENU:=Telephony
DEPENDS:=+modeminfo +telegrambot
TITLE:= Plugin for telegrambot
endef
define Package/$(PKG_NAME)/description
Signal information for 3G/LTE dongle
endef
define Package/$(PKG_NAME)/conffiles
/etc/config/modeminfo
endef
define Build/Prepare
endef
define Build/Configure
endef
define Build/Compile
endef
define Package/$(PKG_NAME)/install
$(INSTALL_DIR) $(1)/usr/bin
$(INSTALL_DIR) $(1)/usr/share/modeminfo
$(INSTALL_DIR) $(1)/usr/share/modeminfo/scripts
$(INSTALL_DIR) $(1)/etc/config
$(CP) ./root/usr/bin/* $(1)/usr/bin
$(CP) ./root/usr/share/modeminfo/mccmnc.dat $(1)/usr/share/modeminfo
$(CP) ./root/usr/share/modeminfo/scripts/*.gcom $(1)/usr/share/modeminfo/scripts/
$(CP) ./root/usr/share/modeminfo/scripts/ch_to_band $(1)/usr/share/modeminfo/scripts/
$(CP) ./root/usr/share/modeminfo/scripts/family.at $(1)/usr/share/modeminfo/scripts/
$(CP) ./root/usr/share/modeminfo/scripts/modeminfo $(1)/usr/share/modeminfo/scripts/
$(CP) ./root/usr/share/modeminfo/scripts/GENERIC* $(1)/usr/share/modeminfo/scripts/
$(CP) ./root/etc/config/* $(1)/etc/config
endef
define Package/$(PKG_NAME)-serial-simcom/install
$(INSTALL_DIR) $(1)/usr/share/modeminfo/scripts
$(CP) ./root/usr/share/modeminfo/scripts/SIMCOM* $(1)/usr/share/modeminfo/scripts
endef
define Package/$(PKG_NAME)-serial-huawei/install
$(INSTALL_DIR) $(1)/usr/share/modeminfo/scripts
$(CP) ./root/usr/share/modeminfo/scripts/HUAWEI* $(1)/usr/share/modeminfo/scripts
endef
define Package/$(PKG_NAME)-serial-quectel/install
$(INSTALL_DIR) $(1)/usr/share/modeminfo/scripts
$(CP) ./root/usr/share/modeminfo/scripts/QUECTEL* $(1)/usr/share/modeminfo/scripts
endef
define Package/$(PKG_NAME)-serial-fibocom/install
$(INSTALL_DIR) $(1)/usr/share/modeminfo/scripts
$(CP) ./root/usr/share/modeminfo/scripts/FIBOCOM* $(1)/usr/share/modeminfo/scripts
endef
define Package/$(PKG_NAME)-serial-telit/install
$(INSTALL_DIR) $(1)/usr/share/modeminfo/scripts
$(CP) ./root/usr/share/modeminfo/scripts/QUALCOMM* $(1)/usr/share/modeminfo/scripts
endef
define Package/$(PKG_NAME)-serial-xmm/install
$(INSTALL_DIR) $(1)/usr/share/modeminfo/scripts
$(CP) ./root/usr/share/modeminfo/scripts/INTEL* $(1)/usr/share/modeminfo/scripts
endef
define Package/$(PKG_NAME)-serial-sierra/install
$(INSTALL_DIR) $(1)/usr/share/modeminfo/scripts
$(CP) ./root/usr/share/modeminfo/scripts/SIERRA* $(1)/usr/share/modeminfo/scripts
endef
define Package/$(PKG_NAME)-serial-dell/install
$(INSTALL_DIR) $(1)/usr/share/modeminfo/scripts
$(CP) ./root/usr/share/modeminfo/scripts/DELL* $(1)/usr/share/modeminfo/scripts
endef
define Package/$(PKG_NAME)-serial-gosun/install
$(INSTALL_DIR) $(1)/usr/share/modeminfo/scripts
$(CP) ./root/usr/share/modeminfo/scripts/GOSUN* $(1)/usr/share/modeminfo/scripts
endef
define Package/$(PKG_NAME)-serial-zte/install
$(INSTALL_DIR) $(1)/usr/share/modeminfo/scripts
$(CP) ./root/usr/share/modeminfo/scripts/ZTE* $(1)/usr/share/modeminfo/scripts
endef
define Package/$(PKG_NAME)-qmi/install
$(INSTALL_DIR) $(1)/usr/share/modeminfo/scripts
$(CP) ./root/usr/share/modeminfo-qmi/* $(1)/usr/share/modeminfo/scripts
endef
define Package/$(PKG_NAME)-telegram/install
$(INSTALL_DIR) $(1)/usr/lib/telegrambot/plugins
$(CP) ./root/usr/lib/telegrambot/plugins/* $(1)/usr/lib/telegrambot/plugins
endef
$(eval $(call BuildPackage,$(PKG_NAME)))
$(eval $(call BuildPackage,$(PKG_NAME)-serial-simcom))
$(eval $(call BuildPackage,$(PKG_NAME)-serial-huawei))
$(eval $(call BuildPackage,$(PKG_NAME)-serial-quectel))
$(eval $(call BuildPackage,$(PKG_NAME)-serial-fibocom))
$(eval $(call BuildPackage,$(PKG_NAME)-serial-telit))
$(eval $(call BuildPackage,$(PKG_NAME)-serial-xmm))
$(eval $(call BuildPackage,$(PKG_NAME)-serial-sierra))
$(eval $(call BuildPackage,$(PKG_NAME)-serial-dell))
$(eval $(call BuildPackage,$(PKG_NAME)-serial-gosun))
$(eval $(call BuildPackage,$(PKG_NAME)-serial-zte))
$(eval $(call BuildPackage,$(PKG_NAME)-qmi))
$(eval $(call BuildPackage,$(PKG_NAME)-telegram))

@ -0,0 +1,2 @@
config modeminfo

@ -0,0 +1,44 @@
#!/bin/sh
function json_status() {
. /usr/share/libubox/jshn.sh
json_init
IFS=$'\n'
for jvar in device=$DEVICE cops=$COPS mode=$MODE csq_per=$CSQ_PER lac=$LAC cid=$CID rssi=$CSQ_RSSI \
sinr=$SINR rsrp=$RSRP rsrq=$RSRQ imei=$IMEI reg=$REGST csq_col=$CSQ_COL arfcn=$EARFCN \
chiptemp=$CHIPTEMP firmware=$FW bwdl=$BWDL lteca=$LTE_CA enbid=$ENBID \
distance=$DISTANCE cell=$CELL scc=$SCC bwca=$BWCA iccid=$ICCID imsi=$IMSI pci=$PCI; do
json_add_string ${jvar%=*} ${jvar#*=}
done
json_close_object
json_dump
}
function if_null() {
for var in DEVICE COPS MODE CSQ_PER LAC CSQ_RSSI SINR RSRP \
RSRQ IMEI REGST EARFCN CHIPTEMP FW BWDL ICCID IMSI; do
if [ "x$(eval echo \${$var})" = "x" ]; then
eval $var='--'
fi
done
}
if [ $(uci -q get modeminfo.@modeminfo[0].qmi_mode) ]; then
SCRIPT=/usr/share/modeminfo/scripts/modeminfo-qmi
else
SCRIPT=/usr/share/modeminfo/scripts/modeminfo
fi
if [ -r $SCRIPT ]; then
. $SCRIPT
else
exit 0
fi
get_device_info
get_data_in >/dev/null 2>&1
if_null
json_status
kill -9 $(pgrep atinout) >/dev/null 2>&1
exit 0

@ -0,0 +1,53 @@
#!/bin/sh
. /usr/share/libubox/jshn.sh
json_load "$(/usr/bin/modeminfo)"
json_get_var DEVICE device
json_get_var COPS cops
json_get_var MODE mode
json_get_var PERS csq_per
echo -ne "*Device:* $DEVICE\n*Operator:* $COPS 📶${PERS}% $MODE\n"
json_get_var CH arfcn
. /usr/share/modeminfo/scripts/ch_to_band
ch_to_band $CH
json_get_var RSSI rssi
case $MODE in
LTE)
json_get_var CA lteca
if [ $CA -ge 1 ]; then
json_get_var SB scc
CA="$(($CA+1))xCA"
BAND="${SC}${SB}"
echo -ne "*CA:* $CA BAND ($BAND)\n"
else
echo -ne "*BAND:* $SC\n"
fi
json_get_var RSRP rsrp
json_get_var RSRQ rsrq
json_get_var SINR sinr
json_get_var ENBID enbid
json_get_var PCI pci
json_get_var CELL cell
json_get_var DIST distance
echo -ne "*RSSI/RSRP:* ${RSSI}dBm/${RSRP}dBm\n*RSRQ/SINR:* ${RSRQ}dB/${SINR}dB\n*eNBID-Cell/PCI:* ${ENBID}-${CELL}/${PCI}"
if [ $DIST ] && [ "$DIST" -ne "0.00" ]; then
echo -ne " ~${DIST}km\n"
else
echo -ne "\n"
fi
;;
UMT*|WCD*|*HSP*|*HUS*)
json_get_var SINR sinr
json_get_var LAC lac
json_get_var CID cid
echo -ne "*BAND:* $SC\n"
echo -ne "*RSSI/ECIO:* ${RSSI}dBm/${SINR}dB\n*LAC/CID:* ${LAC}/${CID}"
;;
*)
json_get_var LAC lac
json_get_var CID cid
echo -ne "*BAND:* $SC\n"
echo -ne "*RSSI:* ${RSSI}dBm\n*LAC/CID:* ${LAC}/${CID}"
;;
esac

@ -0,0 +1,175 @@
# qmi addon for luci-app-modeminfo
# (c) 2020-2022 written by Konstantine Shevlakov (c) at <shevlakov@132lan.ru>
get_device_info(){
DEVPORT=$(uci -q get modeminfo.@modeminfo[0].device_qmi)
if [ -x /usr/bin/qmicli ]; then
export QMICTL="qmicli -p -d $DEVPORT"
else
logger -t "luci-app-modeminfo" "qmicli not found!"
exit 1
fi
if [ $DEVPORT ]; then
QPROXY=$(uci -q get modeminfo.@modeminfo[0].qmi_proxy)
if [ $QPROXY -eq 1 ]; then
export QMICTL="qmicli -p -d $DEVPORT"
else
export QMICTL="qmicli -d $DEVPORT"
fi
else
for qmi in $(ls /dev/cdc-wdm*); do
if [ $qmi ]; then
QMI_DEVICE=$qmi
if [ -n $(which qmicli) ]; then
export QMICTL="qmicli -p -d ${QMI_DEVICE}"
else
logger -t "luci-app-modeminfo" "qmi-utils not found or installed!"
exit 0
fi
else
logger -t "luci-app-modeminfo" "Device is no QMI mode or not found!"
exit 0
fi
done
if [ $qmi ]; then
uci set modeminfo.@modeminfo[0].device_qmi="$qmi"
uci commit modeminfo
break
fi
fi
}
get_hardware_info(){
MANUF=$(${QMICTL} --dms-get-manufacturer | awk -F [:] '/Manufacturer:/{gsub("'\''|^ ", "");print $2}')
MODEL="$($QMICTL --dms-get-model | awk -F [:] '/Model/{gsub("'\''|^ ", "");print $2}')"
if [ -n "$(echo "${MODEL}" | grep -Ei "${MANUF}")" ] || [ -n "$(echo "${MANUF}" | grep -Ei QUAL)" ]; then
DEVICE="${MODEL}"
else
DEVICE="${MANUF} ${MODEL}"
fi
IMEI=`$QMICTL --dms-get-ids | awk -F [:] '/IMEI:/{gsub("'\''|\*", ""); print $2}'`
FW=$($QMICTL --dms-get-software-version | awk -F [:] '/version:/{print $2}' )
ICCID=$($QMICTL --dms-uim-get-iccid | awk -F [:] '/ICCID/{gsub("'\''",""); print $2}' )
}
get_lte_bw(){
case $BWDx in
3) BWDL=1 ;;
5) BWDL=2 ;;
10) BWDL=3 ;;
15) BWDL=4 ;;
20) BWDL=5 ;;
esac
}
get_signal_info(){
NETWORK=`$QMICTL --nas-get-home-network | awk -F [:] '/MCC|MNC|Description/{gsub("'\''|^ ", "");print $2}'`
COPS_MCC=$(echo ${NETWORK} |awk '{print $1}')
COPS_MNC_RAW=$(echo ${NETWORK} |awk '{print $2}')
if [ $COPS_MNC_RAW -lt 10 ]; then
COPS_MNC=0${COPS_MNC_RAW}
else
COPS_MNC=$COPS_MNC_RAW
fi
COPS="$(echo "${NETWORK}" |tail -1)"
SIGNAL=$($QMICTL --nas-get-signal-info)
MODE=$(echo "$SIGNAL" | awk 'NR ==2{gsub("\:", ""); print $1}')
STRENGTH=$(echo "$SIGNAL" | awk '/RSSI|RSRQ|RSRP|SNR|ECIO/{gsub("'\''",""); print $2}')
SERVING=$($QMICTL --nas-get-serving-system)
RFBAND=$($QMICTL --nas-get-rf-band-info)
if [ $MODE == "LTE" ]; then
MIMO=$($QMICTL --nas-get-tx-rx-info=lte | grep 'RX Chain' | wc -l)
LACTAC=$(echo "$SERVING" | awk -F [:] '/tracking area code:|3GPP cell ID:/{gsub("'\''",""); print $2}')
LAC_NUM=$(echo $LACTAC | awk '{print $2}')
CID_NUM=$(echo $LACTAC | awk '{print $1}')
CID=$(echo $CID_NUM | awk '{printf "%x\n", $1}' |awk '{print toupper($1)}')
LAC=$(echo $LAC_NUM | awk '{printf "%x\n", $1}' |awk '{print toupper($1)}')
CSQ_RSSI=$(echo ${STRENGTH} | awk '{print $1}')
RSRQ=$(echo ${STRENGTH} | awk '{print $2}')
RSRP=$(echo ${STRENGTH} | awk '{print $3}')
SINR=$(echo ${STRENGTH} | awk '{printf "%.0f\n", $4}')
ENBx=$(echo $CID | sed -e 's/..$//')
ENBID=$(printf %d 0x$ENBx)
CELL=$(printf %d 0x${CID: -2})
PCI=$($QMICTL --nas-get-cell-location-info | awk -F [:] '/Serving Cell ID:/{gsub("'\''",""); print $2}')
LTE_O=$($QMICTL --nas-get-lte-cphy-ca-info)
LTE_CA=$(echo "$LTE_O" |grep -i '^secondary cell' | wc -l)
BWDx=$(echo "$LTE_O" | grep -A4 'Primary Cell Info' | awk -F [:] '/DL Bandwidth:/{gsub("'\''| ", ""); print $2}')
get_lte_bw
if [ $LTE_CA -ge 1 ]; then
BWC=$(echo "$LTE_O" | grep -A4 '^Secondary Cell' | awk -F [:] '/DL Bandwidth:/{gsub("'\''| ", ""); printf "+"$2}')
BWCA=$(($BWDx$BWC))
BANDCH=$(echo "$LTE_O" | grep -A4 '^Primary Cell' | awk -F [:] '/RX Channel:/{gsub("'\''| ", ""); print $2}')
# Fix qmicli band
case $MANUF in
*DEL*) CA=$(echo "$LTE_O" | grep -A4 '^Secondary Cell' | awk -F [:-] '/LTE Band:/{gsub("'\''| ", ""); printf " "$NF-1}') ;;
*) CA=$(echo "$LTE_O" | grep -A4 '^Secondary Cell' | awk -F [:-] '/LTE Band:/{gsub("'\''| ", ""); print $NF}') ;;
esac
for cc in $CA; do
SCC=$SCC+$cc
done
else
BANDCH=$(echo "$RFBAND" | awk -F [:] '/Active Channel:/{gsub("'\''",""); print $2}')
if [ "x" == "x$BWDx" ]; then
BWDx=$(echo "$RFBAND" | awk -F [:] '/Bandwidth:/{gsub("'\''| ",""); print $2}' | tail -1)
get_lte_bw
fi
fi
EARFCN=$BANDCH
else
MIMO=$($QMICTL --nas-get-tx-rx-info=umts | grep 'RX Chain' | wc -l)
case $MIMO in
0) MIMO=$($QMICTL --nas-get-tx-rx-info=gsm | grep 'RX Chain' | wc -l) ;;
esac
LACTAC=$(echo "$SERVING" | awk -F [:] '/3GPP location area code:|3GPP cell ID:/{gsub("'\''",""); print $2}')
LAC_NUM=$(echo $LACTAC | awk '{print $1}')
CID_NUM=$(echo $LACTAC | awk '{print $2}')
LAC=$(echo $LAC_NUM | awk '{printf "%x\n", $1}' |awk '{print toupper($1)}')
CID=$(echo $CID_NUM | awk '{printf "%x\n", $1}' |awk '{print toupper($1)}')
CSQ_RSSI=$(echo ${STRENGTH} | awk '{print $1}')
if [ $(echo ${STRENGTH} | awk '{print$2}') ]; then
SINR=$(echo ${STRENGTH} | awk '{printf "%.0f\n", $2}')
fi
BANDCH=$(echo "$RFBAND" | awk -F [:] '/Active Channel:/{gsub("'\''| ",""); print $2}')
EARFCN=$(echo $BANDCH | awk '{print $2}')
fi
CSQ_PER=$(echo $CSQ_RSSI |awk '{printf "%d\n", (100*(1-(-50 - $1)/(-50 - -120)))}')
[ $CSQ_RSSI -ge -110 ] && CSQ_COL="black"
[ $CSQ_RSSI -ge -105 ] && CSQ_COL="red"
[ $CSQ_RSSI -ge -95 ] && CSQ_COL="orange"
[ $CSQ_RSSI -ge -75 ] && CSQ_COL="green"
if [ $CSQ_PER -gt 100 ]; then
CSQ_PER=100
elif [ $CSQ_PER -lt 0 ]; then
CSQ_PER=0
fi
EARFCN=$BANDCH
DISTANCE=$($QMICTL --nas-get-cell-location-info | awk '/LTE Timing Advance:/{gsub("\047",""); printf "%.2f\n", (299792458*($4*10^-6)/1000)/2}')
REG=$(echo "$SERVING" | awk -F [:] '/Registration state:/{print $2}' | sed "s/'//g" | awk '{print $1}')
case $REG in
registered)
REGST=1
;;
registration-denied)
REGST=3
;;
esac
if [ $(uci -q get modeminfo.@modeminfo[0].decimail) -eq 1 ]; then
LAC=$LAC_NUM
CID=$CID_NUM
fi
}
#get_device
function get_data_in(){
get_hardware_info >/dev/null 2>&1
get_signal_info >/dev/null 2>&1
}
get_hwinfo(){
continue
}

@ -0,0 +1,79 @@
25001;MTS RUS
25002;MegaFon
25003;ROSTELEKOM
25004;Sibchallenge
25005;ETK
25006;DANYCOM
25007;SMARTS
25009;Skylink
25010;DTC
25011;Yota
25012;Baykal
25013;MTS
25014;MegaFon
25015;SMARTS
25016;NTC
25017;Utel
25018;Астран
25019;Indigo
25020;Tele2
25022;MegaFon
25023;Mobicon
25027;Letai
25028;Beeline
25030;Osttelecom
25032;WIN-Mobile
25033;SevMobile
25034;Krymtelekom
25035;MOTIV
25037;Skylink
25038;ROSTELECOM
25039;ROSTELECOM
25042;MTT
25043;Sprint
25050;Sberbank
25054;Tattelecom
25055;Glonass
25059;Wifire
25060;Volna
25061;Intertelekom
25062;Tinkoff
25077;Glonass
25091;MegaFon
25092;MTS RUS
25099;Beeline
25501;Vodafone
25502;Kyivstar
25503;Kyivstar
25504;Intertelecom
25505;Golden Telecom
25506;life:)
25507;3Mob
25508;Ukrtelecom
25509;Vega
25521;PEOPLEnet
25523;ITC
25525;Newtone
25701;A1
25702;MTS BY
25704;life:)
40101;BeelineKZ
40102;KCell
40107;Altel
40108;Kazakhtelecom
43404;Beeline
43405;Ucell
43407;MobiUz
43408;Uzmobile
43701;Beeline
43703;Fonex
43705;MegaCom
43709;O!
51000;PSN
51001;Indosat Ooredoo
51009;Smartfren
51010;Telkomsel
51011;XL
51027;Net 1
51078;Hinet
51089;3

@ -0,0 +1,71 @@
modem_data(){
# hwinfo
MANUF=$(echo "$O" | grep -i $FAMILY)
MODEL=$(echo "$O" | grep -A1 -i $FAMILY | tail -1)
DEVICE="$MANUF $MODEL"
FW=$(echo "$O" | grep -A2 -i $FAMILY | tail -1)
ICCID=$(echo "$O" | awk -F [:] '/ICCID:/{gsub("\r","");print $2}')
IMEI=$(echo "$O" | grep -A1 -i ICCID | tail -1)
IMSI=$(echo "$O" | grep -A2 -i ICCID | tail -1)
generic_data
if [ "$MODE" = "LTE" ]; then
LAC=$(echo "$O" | awk -F [,] '/\+CEREG/{gsub("\"","");print $3}')
CID=$(echo "$O" | awk -F [,] '/\+CEREG/{gsub("\"","");print $5}')
EARFCN=$(echo "$O" | awk -F [\:/] '/ARFCN/{gsub(" ","", $3); print $3}')
PCI=$(echo "$O" | awk -F [\(,\)] '/PCI/{print $4}')
RSRP=$(echo "$O" | awk '/^RSRP/{gsub("dBm",""); printf "%.0f\n", $2}')
CSQ_RSSI=$(echo "$O" | awk '/^RSSI/{gsub("dBm",""); printf "%.0f\n", $2}')
RSRQ=$(echo "$O" | awk '/^RSRQ/{gsub("dB",""); printf "%.0f\n", $2}')
SINR=$(echo "$O" | awk '/^RS-SINR/{gsub("dB",""); printf "%.0f\n", $2}')
if [ ! $SINR ]; then
SINR=$(echo "$O" | awk '/^RS-SNR/{gsub("dB",""); printf "%.0f\n", $2}')
fi
ENBx=$(echo $CID | sed -e 's/..$//')
CELL=$(printf %d 0x${CID: -2})
ENBID=$(printf %d 0x$ENBx)
BWDx=$(echo "$O" | awk '/PCC info/{printf "%.0f\n",$8}')
LTE_CA=$(echo "$O" | awk '/SCC/{print $0}' | wc -l)
case $BWDx in
3) BWDL=1 ;;
5) BWDL=2 ;;
10) BWDL=3 ;;
15) BWDL=4 ;;
20) BWDL=5 ;;
esac
if [ $LTE_CA -ge 1 ]; then
CA=$(echo "$O" | awk '/SCC/{print $5}')
for cc in $CA; do
SC=$(echo $cc | sed -e 's/LTE_B//g' -e 's/.$//')
SCC="$SCC+$SC"
done
bw=$(echo "$O" |awk '/SCC/{printf "%.0f\n",$8}')
for bwc in $bw; do
bwcc="$bwcc+$bwc"
done
BWCA=$(($BWDx$bwcc))
fi
else
LAC=$(echo "$O" | awk -F [,] '/\+CREG/{gsub("\"","");print $3}')
CID=$(echo "$O" | awk -F [,] '/\+CREG/{gsub("\"","");print $4}')
EARFCN=$(echo "$O" | awk -F [\:/] '/Active channel/{gsub(" ","", $2); print $2}')
RSCP=$(echo "$O" | awk -F [\:\ ,\)/] '/RSCP/{gsub("dBm|)",""); printf "%.0f\n", $7}')
CSQ_RSSI=$(echo "$O" | awk -F [:,] '/QCSQ/{print $2}')
SINR=$(echo "$O" | awk -F [:,] '/QCSQ/{print $3}')
if [ $SINR -le -24 ]; then
SINR=-24
elif [ $SINR -ge 0 ]; then
SINR=0
fi
fi
LAC_NUM=$(printf %d 0x$LAC)
CID_NUM=$(printf %d 0x$CID)
if [ $(uci -q get modeminfo.@modeminfo[0].decimail) -eq 1 ]; then
LAC=$LAC_NUM
CID=$CID_NUM
fi
CHIPTEMP=$(echo "$O" | awk -F [:] '/xo_therm_buf:/{print $2}')
if [ ! $CHIPTEMP ]; then
CHIPTEMP=$(echo "$O" | awk -F [:] '/^TSENS/{gsub("C", ""); print $2}')
fi
}

@ -0,0 +1,11 @@
ATE0
AT+CSQ
AT+COPS=3,2; +COPS?
AT+CREG=2; +CREG?
AT+CGREG=2; +CGREG?
AT+CEREG=2; +CEREG?
AT$QCSQ
AT^DEBUG?
AT^CA_INFO?
AT+TEMP?; AT^TEMP?
AT+CGMI; +CGMM; +CGMR; +ICCID; +CGSN; +CIMI

@ -0,0 +1,67 @@
# Fibocom modems NL668/NL678
function modem_data(){
generic_data
MANUF=$(echo "$O" | awk -F [:,] '/\+CGMI/{gsub("\"","");print $2}')
MODEL=$(echo "$O" | awk -F [:,] '/\+CGMM/{gsub("\"","");print $2}')
DEVICE="$MANUF $MODEL"
FW=$(echo "$O" | awk -F [:,] '/\+CGMR/{gsub("\"","");print $2}')
ICCID=$(echo "$O" | awk -F [:] '/ICCID:/{gsub("\r","");print $2}')
IMSI=$(echo "$O" | awk -F [:,] '/\+CIMI/{gsub("\"","");print $2}')
IMEI=$(echo "$O" | awk -F [:,] '/\+CGSN/{gsub("\"","");print $2}')
NETWORK=$(echo "$O"| grep -A2 'service cell' | awk 'NR ==2{print}')
EARFCN=$(echo "$NETWORK" | awk -F [,] '{print $7}')
if [ "$MODE" = "LTE" ]; then
LAC=$(echo "$O" |awk -F[,\ ] '/^\+CEREG/{gsub("\"","");print $4}')
CID=$(echo "$O" |awk -F[,\ ] '/^\+CEREG/{gsub("\"","");print $5}')
RSRQ=$(echo "$NETWORK" | awk -F [,] '{printf "%.0f\n", -20+($14/2)}')
RSRP=$(echo "$NETWORK" | awk -F [,] '{printf "%.0f\n", $13-140}')
SINR=$(echo "$NETWORK" | awk -F [,] '{printf "%.0f\n", $11/4+5}')
ENBx=$(echo $CID | sed -e 's/..$//')
CELL=$(printf %d 0x${CID: -2})
ENBID=$(printf %d 0x$ENBx)
PCI=$(echo "$NETWORK" | awk -F [,] '{print $8}')
BWDx=$(echo "$NETWORK" | awk -F [,] '{print $10}')
case $BWDx in
15) BWDL=1 BWPx=1.3 ;;
25) BWDL=2 BWPx=5 ;;
50) BWDL=3 BWPx=10 ;;
75) BWDL=4 BWPx=15 ;;
100) BWDL=5 BWPx=20 ;;
esac
LTE_Cx=$(echo "$O" | awk '/^\+GTCAINFO/{print}')
PCH=$(echo "$LTE_Cx" | awk -F [,] '/^\+GTCAINFO: 1/{print $5}')
PCICA=$(echo "$LTE_Cx" | awk -F [,] '/^\+GTCAINFO: 1/{print $4}')
if [ "$EARFCN" = "$PCH" ] && [ "$PCI" = "$PCICA" ]; then
LTE_CA=1
. /usr/share/modeminfo/scripts/ch_to_band
SCH=$(echo "$LTE_Cx" | awk -F [,] '/^\+GTCAINFO: 2\,/{print $(NF-1)}')
BWSx=$(echo "$LTE_Cx" | awk -F [,] '/^\+GTCAINFO: 2\,/{print $NF}')
case $BWSx in
*15*) BWCx=1.3 ;;
*20*) BWCx=5 ;;
*50*) BWCx=10 ;;
*75*) BWCx=15 ;;
*100*) BWCx=20 ;;
esac
BWCA=$(echo $BWPx $BWCx | awk '{print $1+$2}')
ch_to_band $SCH
SCC="+$SC"
fi
else
TECH=$(echo "$O" | awk -F[,\ ] '/^\*CNTI/ {print $3}' | sed 's|/|,|g')
LAC=$(echo "$O" |awk -F[,\ ] '/^\+CGREG/{gsub("\"","");print $4}')
CID=$(echo "$O" |awk -F[,\ ] '/^\+CGREG/{gsub("\"","");print $5}')
if [ "x$TECH" != "x" ]; then
MODE="$TECH"
fi
SINR=$(echo "$NETWORK" | awk -F [,] '{printf "%.0f\n", $NF/2-24}')
fi
LAC_NUM=$(printf %d 0x$LAC)
CID_NUM=$(printf %d 0x$CID)
CHIPTEMP=$(echo "$O" | awk '/\+MTSM/{print $2}')
if [ $(uci -q get modeminfo.@modeminfo[0].decimail) -eq 1 ]; then
LAC=$LAC_NUM
CID=$CID_NUM
fi
}

@ -0,0 +1,8 @@
ATE0
AT+COPS=3,2; +COPS?;
AT+CEREG=2; +CEREG?
AT+CGREG=2; +CGREG?; +CSQ
AT+GTCCINFO?; +GTCAINFO?
AT*CNTI=0
AT+MTSM=1
AT+CGMI?; +CGMM?; +CGMR?; +CIMI?; +ICCID; +CGSN?

@ -0,0 +1,5 @@
# Generic modem data
modem_data(){
REGST=$(echo "$O" | awk -F[,] '/\+CREG/ {print $2}')
generic_data
}

@ -0,0 +1,6 @@
ATE0
AT+CSQ
AT+COPS=3,2; +COPS?
AT+CREG=2; +CREG?
AT+CGREG=2; +CGREG?
AT+CGMI; +CGMM; +CGMR; +ICCID; +CGSN; +CIMI

@ -0,0 +1,53 @@
function modem_data(){
DATA=$(echo "$O" | grep -Ev '^OK')
MANUF=$(echo "$DATA" | awk 'c&&! --c;/ZCHIPTEMP/{c=1}')
MODEL=$(echo "$DATA" | awk 'c&&! --c;/ZCHIPTEMP/{c=2}')
FW=$(echo "$DATA" | awk 'c&&! --c;/ZCHIPTEMP/{c=3}')
DEVICE="$MANUF $MODEL"
TECH=$(echo "$DATA" | awk -F [,] '/\+COPS/{print $NF}')
ICCID=$(echo "$DATA" | awk '/ZGETICCID/{print $2}')
IMSI=$(echo "$DATA" | awk 'c&&! --c;/ZGETICCID/{c=1}')
IMEI=$(echo "$DATA" | awk 'c&&! --c;/ZGETICCID/{c=2}')
CHIPTEMP=$(echo "$DATA" | awk '/\+ZCHIPTEMP/{print $2}')
case $TECH in
0|1) MODE=GSM ;;
2) MODE=WCDMA ;;
3) MODE=EDGE ;;
4) MODE=HSDPA ;;
5) MODE=HSUPA ;;
6) MODE=HSDPA,HSUPA ;;
7) MODE=LTE ;;
8) MODE=DC-HSPA+ ;;
esac
case $TECH in
7)
PCI=$(echo "$DATA" | awk -F [:,] '/\+ZCDS/{print $10}')
EEMGINFO=$(echo "$O" | awk -F[':'] '/^\+EEMLTESVC:/ {print $2}')
EARFCN=$(echo $EEMGINFO | awk -F [,] '{print $6}')
LAC=$(echo $EEMGINFO | awk -F [,] '{printf "%x\n", toupper($4)}')
CID=$(echo $EEMGINFO | awk -F [,] '{printf "%x\n", toupper($21)}')
ENBx=$(echo $CID | sed -e 's/..$//')
ENBID=$(printf %d 0x$ENBx)
CELL=$(printf %d 0x${CID: -2})
PCI=$(echo $EEMGINFO | awk -F [,] '{print $5}')
RSRQ=$(echo $EEMGINFO | awk -F[,] '{printf "%.0f\n", -19.5+$11/2}')
RSRP=$(echo $EEMGINFO | awk -F[,] '{print -140+$10'})
SINR=$(echo $EEMGINFO | awk -F[','] '{printf "%.0f\n", $12/4+5}')
BWDL=$(echo $EEMGINFO | awk -F[','] '{print $9}')
;;
2|4|5|6|8)
EEMGINFO=$(echo "$O" | awk -F[':'] '/^\+EEMUMTSSVC/ {print $2}')
EARFCN=$(echo $EEMGINFO | awk -F [,] '{print $20}')
SINR=$(echo $EEMGINFO | awk -F [,] '{printf "%.0f\n", -24+$6/2}')
LAC=$(echo $EEMGINFO | awk -F [,] '{printf "%x\n", toupper($16)}')
CID=$(echo $EEMGINFO | awk -F [,] '{printf "%x\n", toupper($17)}')
;;
esac
if [ $(uci -q get modeminfo.@modeminfo[0].decimail) -eq 1 ]; then
LAC=$(printf %d 0x$LAC)
CID=$(printf %d 0x$CID)
fi
}

@ -0,0 +1,5 @@
ATE0
AT+COPS=3,2; +COPS?; +CREG?; +CGREG?; +CGREG?; +CEREG?; +CSQ
AT+EEMGINFO?
AT+ZCHIPTEMP?
AT+CGMI; +CGMM; +CGMR; +ZGETICCID; +CIMI ;+CGSN

@ -0,0 +1,90 @@
# Huawei modems
function modem_data(){
MANUF=$(echo "$O" | grep -i $FAMILY)
MODEL=$(echo "$O" | grep -A1 -i $FAMILY | tail -1)
DEVICE="$MANUF $MODEL"
FW=$(echo "$O" | grep -A2 -i $FAMILY | tail -1)
ICCID=$(echo "$O" | awk '/ICCID/{print $2}')
IMSI=$(echo "$O" | grep -A1 -i ICCID |tail -1)
IMEI=$(echo "$O" | grep -A2 -i ICCID |tail -1)
LAC=$(echo "$O" |awk -F[,\ ] '/^\+CGREG/{gsub("\"","");print $4}')
CID=$(echo "$O" |awk -F[,\ ] '/^\+CGREG/{gsub("\"","");print $5}')
LAC_NUM=$(printf %d 0x$LAC)
CID_NUM=$(printf %d 0x$CID)
# Huawei any modern models
TECH=$(echo "$O" | awk -F[,] '/^\^SYSINFOEX/ {print $9}' | sed 's/"//g')
if [ "x$TECH" != "x" ]; then
MODE=$(echo "$TECH" | sed 's/-//g')
fi
# Huawei and older models
if [ "x$MODE" = "x-" ] || [ "x$TECH" = "x" ]; then
TECH=$(echo "$O" | awk -F[,] '/^\^SYSINFO/ {print $7}')
case $TECH in
17*) MODE="HSPA+ (64QAM)";;
18*) MODE="HSPA+ (MIMO)";;
1*) MODE="GSM";;
2*) MODE="GPRS";;
3*) MODE="EDGE";;
4*) MODE="UMTS";;
5*) MODE="HSDPA";;
6*) MODE="HSUPA";;
7*) MODE="HSPA";;
9*) MODE="HSPA+";;
*) MODE="-";;
esac
fi
EARFCN=$(echo "$O" | awk -F[,\ ] '/^\^HFREQINFO/ {print $4}')
BWDx=$(echo "$O" | awk -F[,\ ] '/^\^HFREQINFO/ {print $6}')
RSRx=$(echo "$O" | awk -F[,:] '/^\^LTERSRP:/ {print $2}')
if [ "x$RSRx" != "x" ]; then
RSRP=$RSRx
RSRQ=$(echo "$O" | awk -F[,:] '/^\^LTERSRP:/ {print $3}')
elif [ "x$RSRx" = "x" ]; then
ECIO=$(echo "$O" | awk -F[,:] '/^\^CSNR:/ {print $3}')
SINR=$ECIO
fi
TECH=$(echo "$O" | awk -F[,:] '/^\^HCSQ:/ {print $2}' | sed 's/[" ]//g')
if [ "x$TECH" != "x" ]; then
PARAM1=$(echo "$O" | awk -F[,:] '/^\^HCSQ:/ {print $3}')
PARAM2=$(echo "$O" | awk -F[,:] '/^\^HCSQ:/ {print $4}')
PARAM3=$(echo "$O" | awk -F[,:] '/^\^HCSQ:/ {print $5}')
PARAM4=$(echo "$O" | awk -F[,:] '/^\^HCSQ:/ {print $6}')
case "$TECH" in
WCDMA*)
CSQ_RSSI=$(awk 'BEGIN {print -121 + '$PARAM1'}')
RSCP=$(awk 'BEGIN {print -121 + '$PARAM2'}')
ECIO=$(awk 'BEGIN {print -32.5 + '$PARAM3'/2}')
SINR=$ECIO
;;
LTE*)
PCI=$(echo "$O" | awk -F [,] '/MONSC/{print $6}')
ENBx=$(echo $CID | sed -e 's/..$//')
CELL=$(printf %d 0x${CID: -2})
ENBID=$(printf %d 0x$ENBx)
CSQ_RSSI=$(awk 'BEGIN {print -121 + '$PARAM1'}')
RSRP=$(awk 'BEGIN {print -141 + '$PARAM2'}')
SINR=$(awk 'BEGIN {print -20.2 + '$PARAM3'/5}')
RSRQ=$(awk 'BEGIN {print -20 + '$PARAM4'/2}')
;;
esac
fi
CHIPTEMP=$(echo "$O" | awk -F[,] '/^\^CHIPTEMP/ {print $4}')
# 65535 -> Not supported currently
if [ $CHIPTEMP -eq 65535 ]; then
# CHIPTEMP for Huawei ME909u series
CHIPTEMP=$(echo "$O" | awk -F[,] '/^\^CHIPTEMP/ {printf "%.0f\n", $6 * 0.1}')
fi
case $BWDx in
1400) BWDL=0 ;;
3000) BWDL=1 ;;
5000) BWDL=2 ;;
10000) BWDL=3 ;;
15000) BWDL=4 ;;
20000) BWDL=5 ;;
esac
if [ $(uci -q get modeminfo.@modeminfo[0].decimail) -eq 1 ]; then
LAC=$LAC_NUM
CID=$CID_NUM
fi
}

@ -0,0 +1,7 @@
ATE0
AT+COPS=3,2;
AT+COPS?; +CREG?; +CSQ
AT+CGREG=2
AT+CGREG?; ^MONSC
AT^HFREQINFO?; ^SYSINFOEX; ^LTERSRP?; ^CSNR?; ^HCSQ?; ^CHIPTEMP?; ^SYSCFGEX?
AT+CGMI; +CGMM; +CGMR; ^ICCID?; +CIMI; +CGSN

@ -0,0 +1,105 @@
function modem_data(){
generic_data
. /usr/share/modeminfo/scripts/ch_to_band
FW=$(echo "$O" | awk '/\+GTPKGVER/{gsub("\"",""); print $2}')
ICCID=$(echo "$O" | awk '/CCID:/{print $2}')
IMSI=$(echo "$O" | grep -A1 CCID | tail -1)
IMEI=$(echo "$O" | grep -A2 CCID | tail -1)
DEVx="$(echo "$O" | awk -F [:,] '/CGMI:|GMM:/{gsub("\"|\r","",$0); print substr($2,2);}')"
DEVICE=$(echo $DEVx)
if [ $MODE = LTE ]; then
EARFCN=$(echo "$O" | awk -F [:,] '/\+RSRP:/{print $3}')
DISTANCE=$(echo "$O" | awk -F [:,] '/\+XMCI: 4/{gsub(/"/,""); printf "%.2f\n", ($14*78)/1000}')
PCI=$(echo "$O" | awk -F [:,] '/\+XMCI: 4/{gsub(/"/,""); printf "%d\n", $7}')
RSRP=$(echo "$O" | awk -F [:,] '/\+RSRP:/{printf "%.0f\n", $4}')
RSRQ=$(echo "$O" | awk -F [:,] '/\+RSRQ:/{printf "%.0f\n", $4}')
REGST=$(echo "$O" | awk -F[,] '/\+CEREG/ {print $2}')
LAC=$(echo "$O" | awk -F [,] '/\+CEREG/{gsub("\"","");print $3}')
CID=$(echo "$O" | awk -F [,] '/\+CEREG/{gsub("\"","");print $4}')
# ! SINR formula needs to be checked !
SINR=$(echo "$O" | awk -F [:,] '/\+XMCI: 4/{gsub(/"/,""); printf "%.0f\n", $13/4+5}')
LTE_Cx=$(echo "$O" | awk -F [:,] '/\+XLEC:/{print $3}')
LTE_CA=$(($LTE_Cx -1))
BWDL=$(echo "$O" | awk -F [:,] '/\+XLEC:/{gsub("\r","",$4); print $4}')
ENBx=$(echo $CID | sed -e 's/..$//')
CELL=$(printf %d 0x${CID: -2})
ENBID=$(printf %d 0x$ENBx)
case $BWDL in
1) NP=15 ;;
2) NP=25 ;;
3) NP=50 ;;
4) NP=75 ;;
5) NP=100 ;;
*) NP=0 ;;
esac
CSQ=$(echo $RSRP $NP | awk '{printf "%.0f\n", (($1+10*log(12*$2)/log(10))+113)/2}')
[ "x$CSQ" = "x" ] && CSQ=-1
if [ $CSQ -ge 0 -a $CSQ -le 31 ]; then
CSQ_PER=$(($CSQ * 100/31))
CSQ_COL="red"
[ $CSQ -ge 10 ] && CSQ_COL="red"
[ $CSQ -ge 15 ] && CSQ_COL="orange"
[ $CSQ -ge 20 ] && CSQ_COL="green"
CSQ_RSSI=$((2 * CSQ - 113))
# Fibocom RSSI up -51dBm. Thanks to TSA74 at 4pda.to
elif [ $CSQ -ge 32 -a $CSQ -le 50 ]; then
CSQ_PER="100"
CSQ_COL="green"
CSQ_RSSI=$((2 * CSQ - 113))
else
CSQ_PER="0"
CSQ_COL="black"
fi
case $LTE_CA in
1)
SCx=$(echo "$O" | awk -F [:,] '/\+RSRP:/{print $6}')
BWCx=$(echo "$O" | awk -F [:,] '/\+XLEC/{gsub("\r",""); print $4" "$5}')
;;
2)
SCx=$(echo "$O" | awk -F [:,] '/\+RSRP:/{print $6" "$9}')
BWCx=$(echo "$O" | awk -F [:,] '/\+XLEC/{gsub("\r",""); print $4" "$5" "$6}')
;;
3)
SCx=$(echo "$O" | awk -F [:,] '/\+RSRP:/{print $6" "$9" "$12}')
BWCx=$(echo "$O" | awk -F [:,] '/\+XLEC/{gsub("\r",""); print $4" "$5" "$6" "$7}')
;;
4)
SCx=$(echo "$O" | awk -F [:,] '/\+RSRP:/{print $6" "$9" "$12" "$15}')
BWCx=$(echo "$O" | awk -F [:,] '/\+XLEC/{gsub("\r",""); print $4" "$5" "$6" "$7" "$8}')
;;
esac
for ca in $BWCx; do
case $ca in
1) N=3 ;;
2) N=5 ;;
3) N=10 ;;
4) N=15 ;;
5) N=20 ;;
*) N=0 ;;
esac
BWCA=$(($BWCA+$N))
done
for sca in $SCx; do
ch_to_band $sca
SCC=$SCC+$SC
done
else
REGST=$(echo "$O" | awk -F[,] '/\+CREG/ {print $2}')
LAC=$(echo "$O" | awk -F [,] '/\+CREG/{gsub("\"","");print $3}')
CID=$(echo "$O" | awk -F [,] '/\+CREG/{gsub("\"","");print $4}')
EARFCN=$(echo "$O" | awk -F [:,] '/\+RSCP:/{print $3}')
SINx=$(echo "$O" | awk -F [:,] '/\+XCESQ:/{print $6}')
if [ $SINx -eq 99 ]; then
SINR=""
else
SINR=$(echo "$O" | awk -F [:,] '/\+XCESQ:/{printf "%.0f\n", ($6-50)/2}')
fi
fi
LAC_NUM=$(printf %d 0x$LAC)
CID_NUM=$(printf %d 0x$CID)
if [ $(uci -q get modeminfo.@modeminfo[0].decimail) -eq 1 ]; then
LAC=$LAC_NUM
CID=$CID_NUM
fi
CHIPTEMP=$(echo "$O" | awk -F[:,] '/\+MTSM:/{print $2}')
}

@ -0,0 +1,9 @@
ATE0
AT+COPS=3,2; +COPS?
AT+CEREG=2; +CEREG?
AT+CREG=2; +CREG?; +CSQ?
AT+XCESQ?; +RSRP?; +RSRQ?; +RSCP?
AT+XLEC?
AT+MTSM=1
AT+XMCI=1
AT+GTPKGVER?; +CGMI; +GMM?; +CCID; +CIMI; +CGSN

@ -0,0 +1,80 @@
# MikroTik R11e-LTE, R11e-LTE6 modem (plat.ver."OpenWrt-18.06.7" router: MikroTik RBM33")
# NEED REWRITE FUNCTION for atinout compatible!!!
function modem_data() {
TECH=$(echo "$O" | awk -F[,] '/^\+COPS/ {print $4}')
EEMGSTATE=-1
case "$TECH" in
0*|1*) # GSM, GSM Compact
MODE="GSM"
EEMGSTATE=0
;;
2*) # UTRAN
MODE="UMTS"
EEMGSTATE=0
;;
3*) # GSM w/EGPRS
MODE="EDGE"
EEMGSTATE=0
;;
4*|5*) # UTRAN w/HSDPA, UTRAN w/HSUPA
MODE="HSDPA"
EEMGSTATE=1
;;
6*) # UTRAN w/HSDPA and HSUPA
MODE="HSUPA"
EEMGSTATE=1
;;
7*) # E-UTRAN
MODE="LTE"
EEMGSTATE=2
;;
8*) # UTRAN HSPA+
MODE="HSPA"
EEMGSTATE=2
;;
*)
MODE="--"
;;
esac
DEVx="$(echo "$O" | awk -F [:,] '/CGMI:|GMM:/{gsub("\"|\r","",$0);print substr($2,2);}')"
DEVICE=$(echo $DEVx)
IMEI=$(echo echo "$O" | awk -F [:,] '/\+CGSN:/{gsub(" ","", $2); print $2}')
CSQ_RSSI=$(echo "$O" | awk -F[':,'] '/^\+CESQ:/ {print $2}')
ECIO=$(echo "$O" | awk -F[':,'] '/^\+CESQ:/ {print $5}')
# If less than 11 -> error
if [ "x$CSQ_RSSI" != "x" ]; then
CSQ_RSSI=$(echo $CSQ_RSSI | awk '{if((110 - $1) > 11) print 110 - $1; else print "";}')
fi
if [ "x$ECIO" != "x" ]; then
ECIO=$(echo $ECIO | awk '($1 < 255) {print 25 - $1 * 0.5}')
fi
# LTE Engineering Mode
if [ $EEMGSTATE -eq 2 ]; then
EEMGINFO=$(echo "$O" | awk -F[':'] '/^\+EEMLTESVC:/ {print $2}')
if [ "x$EEMGINFO" != "x" ]; then
BW=$(echo $EEMGINFO | awk -F[','] '{print $8}')
BWDL=$(echo $EEMGINFO | awk -F[','] '{print $9}')
RSRP=$(echo $EEMGINFO | awk -F[','] '{print $11}')
RSRQ=$(echo $EEMGINFO | awk -F[','] '{print $12}')
SINR=$(echo $EEMGINFO | awk -F[','] '{print $13}')
COPS_MCC=$(echo $EEMGINFO | awk -F[','] '{print $1}')
COPS_MNC=$(echo $EEMGINFO | awk -F[','] '{print $3}')
EARFCN=$(echo $EEMGINFO | awk -F[','] '{print $6}')
fi
# UMTS Engineering Mode
elif [ $EEMGSTATE -eq 1 ]; then
COPS_NUM=$(echo "$O" | awk -F[":"] '/^\+EEMUMTSSV:/ {print $2}')
if [ "x$EEMGINFO" != "x" ]; then
COPS_MCC=$(echo $EEMGINFO | awk -F[','] '{print $11}')
COPS_MNC=$(echo $EEMGINFO | awk -F[','] '{print $12}')
SINR=$ECIO
fi
# GSM Engineering Mode
elif [ $EEMGSTATE -eq 0 ]; then
COPS_NUM=$(echo "$O" | awk -F[":"] '/^\+EEMGINFOSVC:/ {print $2}')
if [ "x$EEMGINFO" != "x" ]; then
COPS_MCC=$(echo $EEMGINFO | awk -F[','] '{print $1}')
COPS_MNC=$(echo $EEMGINFO | awk -F[','] '{print $2}')
fi
fi
}

@ -0,0 +1,8 @@
ATE0
AT+COPS=3,2; +COPS?
AT+CREG=2; +CREG?
AT+CGREG=2; +CGREG?
AT+CEREG=2; +CEREG?
AT+EEMOPT=1
AT+EEMGINFO?
AT+CGMI; +CGMM; +CGMR; +ICCID; +CGSN; +CIMI

@ -0,0 +1,62 @@
# Qualcomm Modems (FoxConn T77W678, Telit LN940, HP LT4220)
function modem_data(){
generic_data
# hwinfo
MANUF=$(echo "$O" | grep -i $FAMILY)
MODEL=$(echo "$O" | grep -A1 -i $FAMILY | tail -1)
DEVICE="$MANUF $MODEL"
FW=$(echo "$O" | grep -A2 -i $FAMILY | tail -1)
ICCID=$(echo "$O" | awk -F [:] '/ICCID:/{gsub("\r","");print $2}')
IMSI=$(echo "$O" | grep -A1 -i ICCID | tail -1)
IMEI=$(echo "$O" | grep -A2 -i ICCID | tail -1)
# signal
RADIODATA=$(echo "$O" |grep -A2 RFSTS: | awk 'NR ==2{print $0}')
LTE_CA=$(echo "$O" | awk '/SCC/{print $0}' | wc -l)
EARFCN=$(echo "$RADIODATA" |awk -F [,] '{print $2}')
if [ "$MODE" = "LTE" ]; then
REGST=$(echo "$O" | awk -F[,] '/\+CEREG/ {print $2}')
LAC=$(echo "$O" | awk -F [,] '/\+CEREG/{gsub("\"","");print $3}')
CID=$(echo "$O" | awk -F [,] '/\+CEREG/{gsub("\"","");print $5}')
RSRP=$(echo "$RADIODATA" |awk -F [,] '{printf "%.0f\n",$3}')
CSQ_RSSI=$(echo "$RADIODATA" |awk -F [,] '{printf "%.0f\n",$4}')
RSRQ=$(echo "$RADIODATA" |awk -F [,] '{printf "%.0f\n",$5}')
SINR=$(echo "$RADIODATA" |awk -F [,] '{printf "%.0f\n",$16/4+5}')
BWDx=$(echo "$O" | awk '/PCC info/{printf "%.0f\n",$8}')
PCI=$(echo "$RADIODATA" |awk -F [,] '{print $11}')
ENBx=$(echo $CID | sed -e 's/..$//')
CELL=$(printf %d 0x${CID: -2})
ENBID=$(printf %d 0x$ENBx)
case $BWDx in
3) BWDL=1 ;;
5) BWDL=2 ;;
10) BWDL=3 ;;
15) BWDL=4 ;;
20) BWDL=5 ;;
esac
if [ $LTE_CA -ge 1 ]; then
CA=$(echo "$O" | awk '/SCC/{print $5}')
for cc in $CA; do
SC=$(echo $cc | sed -e 's/LTE_B//g' -e 's/.$//')
SCC="$SCC+$SC"
done
bw=$(echo "$O" |awk '/SCC/{printf "%.0f\n",$8}')
for bwc in $bw; do
bwcc="$bwcc+$bwc"
done
BWCA=$(($BWDx$bwcc))
fi
else
LAC=$(echo "$O" | awk -F [,] '/\+CREG/{gsub("\"","");print $3}')
CID=$(echo "$O" | awk -F [,] '/\+CREG/{gsub("\"","");print $4}')
ECIO=$(echo "$RADIODATA" |awk -F [,] '{printf "%.0f\n",$4}')
CSQ_RSSI=$(echo "$RADIODATA" |awk -F [,] '{printf "%.0f\n",$6}')
SINR=$ECIO
fi
CHIPTEMP=$(echo "$O" | awk -F [:] '/tsens_tz_sensor0:/{print $2}')
LAC_NUM=$(printf %d 0x$LAC)
CID_NUM=$(printf %d 0x$CID)
if [ $(uci -q get modeminfo.@modeminfo[0].decimail) -eq 1 ]; then
LAC=$LAC_NUM
CID=$CID_NUM
fi
}

@ -0,0 +1,10 @@
ATE0
AT+COPS=3,2; +COPS?
AT+CREG=2; +CREG?
AT+CGREG=2; +CGREG?
AT+CEREG=2; +CEREG?
AT+CSQ
AT^RFSTS?
AT^CA_INFO?
AT+TEMP
AT+CGMI; +CGMM; +CGMR; +ICCID; +CIMI; +CGSN

@ -0,0 +1,98 @@
# Quectel modems
function modem_data(){
generic_data
# hwinfo
MANUF=$(echo "$O" | grep -i $FAMILY)
MODEL=$(echo "$O" | grep -A1 -i $FAMILY | tail -1)
DEVICE="$MANUF $MODEL"
FW=$(echo "$O" | grep -A2 -i $FAMILY | tail -1)
ICCID=$(echo "$O" | awk -F [:] '/ICCID:/{gsub("\r","");print $2}')
case $MODEL in
*EC200*)
IMSI=$(echo "$O" | grep -A3 -i $FAMILY | tail -1)
IMEI=$(echo "$O" | grep -A4 -i $FAMILY | tail -1)
;;
*EC25*|*EP06*|*EM160*)
IMSI=$(echo "$O" | grep -A1 -i $FW | tail -1)
IMEI=$(echo "$O" | grep -A1 -i $ICCID | tail -1)
;;
*)
IMSI=$(echo "$O" | grep -A1 -i ICCID | tail -1)
IMEI=$(echo "$O" | grep -A2 -i ICCID | tail -1)
;;
esac
# signal info
if [ "$MODE" = "LTE" ]; then
EARFCN=$(echo "$O" |awk -F[,\ ] '/^\+QENG/ {print $10}')
RSRP=$(echo "$O" |awk -F[,\ ] '/^\+QENG/ {print $15}')
SINR=$(echo "$O" |awk -F "[\, ]" '/\+QENG:/{print $18}')
PCI=$(echo "$O" |awk -F "[\, ]" '/\+QENG:/{print $9}')
CID=$(echo "$O" |awk -F "[\, ]" '/\+QENG:/{print $8}')
LAC=$(echo "$O" |awk -F "[\, ]" '/\+QENG:/{print $14}')
ENBx=$(echo $CID | sed -e 's/..$//')
CELL=$(printf %d 0x${CID: -2})
ENBID=$(printf %d 0x$ENBx)
case $MODEL in
# EC200 send incorrect RSSI value, use value from AT+CSQ
*EC200*) continue ;;
*) CSQ_RSSI=$(echo "$O" |awk -F "[\, ]" '/\+QENG:/{print $17}') ;;
esac
RSRQ=$(echo "$O" |awk -F[,\ ] '/^\+QENG/ {print $16}')
BWUL=$(echo "$O" |awk -F[,\ ] '/^\+QENG/ {print $12}')
BWDL=$(echo "$O" |awk -F[,\ ] '/^\+QENG/ {print $13}')
LTE_CA=$(echo "$O" | awk '/^\+QCAINFO/{print $0}' | wc -l)
if [ $LTE_CA -ge 2 ]; then
CA_INFO=$(echo "$O" | awk '/^\+QCAINFO/{print $0}' | awk '/scc/{print $0}')
CA=$(echo "$CA_INFO" | awk -F [\,] '{print $4}' | awk '{print $3}' | sed 's/\"//g')
BWC=$(echo "$CA_INFO" | awk -F [\,] '{print $3}')
for cc in $CA; do
SC=$cc
SCC="$SCC+$SC"
done
case $BWDL in
1) BWCP=3 ;;
2) BWCP=5 ;;
3) BWCP=10 ;;
4) BWCP=15 ;;
5) BWCP=20 ;;
esac
for BW in $BWC; do
case $BW in
15) BWCC=3 ;;
25) BWCC=5 ;;
50) BWCC=10 ;;
75) BWCC=15 ;;
100) BWCC=20 ;;
esac
BWCA="$BWCA+$BWCC"
done
BWCA=$(($BWCP$BWCA))
fi
elif [ "$MODE" = "EDGE" ]; then
LAC=$(echo "$O" |awk -F[,\ ] '/^\+QENG/ {print $6}')
CID=$(echo "$O" |awk -F[,\ ] '/^\+QENG/ {print $7}')
EARFCN=$(echo "$O" |awk -F[,\ ] '/^\+QENG/ {print $10}')
else
LAC=$(echo "$O" |awk -F[,\ ] '/^\+QENG/ {print $7}')
CID=$(echo "$O" |awk -F[,\ ] '/^\+QENG/ {print $8}')
EARFCN=$(echo "$O" |awk -F[,\ ] '/^\+QENG/ {print $9}')
ECIO=$(echo "$O" |awk -F[,\ ] '/^\+QENG/ {print $13}')
SINR=$ECIO
fi
case $MODEL in
*EM160*) CHIPTEMP=$(echo "$O" | awk -F[,\ ] '/^\+QTEMP: \"cpu-usr\"/ {gsub("\"","");print $3}') ;;
*)
CHIPTEMP=$(echo "$O" | awk -F[,\ ] '/^\+QTEMP/ {print $3}')
# Quectel EM1X modem temp sensors
if [ ! $(echo "$CHIPTEMP" | grep "^?[0-9]+$") ] || [ $CHIPTEMP -eq 255 ]; then
CHIPTEMP=$(echo "$O" | awk -F[,\ ] '/^\+QTEMP/ {gsub("\"",""); print $2}')
fi
;;
esac
LAC_NUM=$(printf %d 0x$LAC)
CID_NUM=$(printf %d 0x$CID)
if [ $(uci -q get modeminfo.@modeminfo[0].decimail) -eq 1 ]; then
LAC=$LAC_NUM
CID=$CID_NUM
fi
}

@ -0,0 +1,6 @@
ATE0
AT+COPS=3,2; +COPS?; +CREG?; +CGREG?; +CGREG?; +CEREG?; +CSQ
AT+QENG="servingcell"
AT+QCAINFO
AT+QTEMP
AT+CGMI; +CGMM; +CGMR; +CIMI; +ICCID; +CGSN

@ -0,0 +1,73 @@
modem_data(){
# hwdata
MANUF=$(echo "$O" | grep -i $FAMILY)
MODEL=$(echo "$O" | grep -A1 -i $FAMILY | tail -1)
DEVICE="$MANUF $MODEL"
FW=$(echo "$O" | grep -A2 -i $FAMILY | tail -1)
ICCID=$(echo "$O" | awk -F [:] '/ICCID:/{gsub("\r","");print $2}')
IMSI=$(echo "$O" | grep -A1 -i ICCID | tail -1)
IMEI=$(echo "$O" | grep -A2 -i ICCID | tail -1)
# Sierra cell data
TECH=$(echo "$O" | awk -F[,\ ] '/^\*CNTI/ {print $3}' | sed 's|/|,|g')
if [ "x$TECH" != "x" ]; then
MODE="$TECH"
fi
if [ $MODE = "LTE" ]; then
# Sierra 73XX series
LAC=$(echo "$O" | awk -F [,] '/\+CEREG/{gsub("\"","");print $3}')
CID=$(echo "$O" | awk -F [,] '/\+CEREG/{gsub("\"","");print $5}')
EARFCN=$(echo "$O" | awk '/LTE Rx chan:/{print $4}')
RSRP=$(echo "$O" | awk '/RSRP/{print $3}' | head -1)
RSRQ=$(echo "$O" | awk '/RSRQ/{printf "%.0f\n", $3}' |head -1)
SINx=$(echo "$O" | awk '/SINR/{print $6}' |head -1)
SINR=$(echo $SINx | awk '{printf "%.0f\n", $0}')
CSQ_RSSI=$(echo "$O" | awk '/PCC RxM RSSI:/{print $4}')
LTE_CA=$(echo "$O" | awk '/SCC RxM RSSI:/{print $0}' |wc -l)
BWDx=$(echo "$O" | awk '/LTE bw/{print $6}')
ENBx=$(echo $CID | sed -e 's/..$//')
CELL=$(printf %d 0x${CID: -2})
ENBID=$(printf %d 0x$ENBx)
PCI=$(echo "$O" | awk -F [:,] '/QCRSRQ:/{print $2}')
if [ $LTE_CA -ge 1 ]; then
CA=$(echo "$O" | awk -F [:] '/LTE Scell band/{gsub("B","");print $3}')
for cc in "$CA"; do
SC=$cc
SCC="$SCC+$cc"
done
bw=$(echo "$O" |awk '/LTE Scell bw:/{gsub("bw:","");print $3}')
for bwc in $bw; do
bwcc="$bwcc+$bwc"
done
BWCA=$(($BWDx$bwcc))
fi
case $BWDx in
3) BWDL=1 ;;
5) BWDL=2 ;;
10) BWDL=3 ;;
15) BWDL=4 ;;
20) BWDL=5 ;;
esac
# Sierra 74XX series
if [ "x$SINx" = "x" ]; then
SINR=$(echo "$O" | awk '/SINR/{printf "%.0f\n", $3}' |head -1)
RSRP=$(echo "$O" | awk '/RSRP/{print $7}' | head -1)
fi
else
LAC=$(echo "$O" | awk -F [,] '/\+CGREG/{gsub("\"","");print $3}')
CID=$(echo "$O" | awk -F [,] '/\+CGREG/{gsub("\"","");print $4}')
EARFCN=$(echo "$O" | awk '/channel:/{print $3}')
SINR=$(echo "$O" | awk -F [:,] '/QCSQ/{print $3}')
if [ $SINR -ge 0 ]; then
SINR=0
elif [ $SINR -le -20 ]; then
SINR=-20
fi
fi
CHIPTEMP=$(echo "$O" | awk '/Temperature:/{print $5}')
LAC_NUM=$(printf %d 0x$LAC)
CID_NUM=$(printf %d 0x$CID)
if [ $(uci -q get modeminfo.@modeminfo[0].decimail) -eq 1 ]; then
LAC=$LAC_NUM
CID=$CID_NUM
fi
}

@ -0,0 +1,11 @@
ATE0
AT+COPS=3,2;+COPS?
AT+CREG=2;+CREG?
AT+CGREG=2;+CGREG?
AT+CEREG=2;+CEREG?
AT+CSQ
AT*CNTI=0
AT!GSTATUS?
AT$QCRSRQ?
AT$QCSQ
AT+CGMI; +CGMM; +CGMR; +ICCID; +CIMI; +CGSN

@ -0,0 +1,90 @@
# SimCom SIM7600E-H
modem_data(){
# get hardware info
MANUF=$(echo "$O" | grep -i ${FAMILY} | head -1)
MODEL=$(echo "$O" | grep -i ${FAMILY} | tail -1)
DEVICE="$MANUF $MODEL"
FW=$(echo "$O" | awk '/\+CGMR:/{print $2}')
ICCID=$(echo "$O" | awk -F [:] '/ICCID:/{gsub("\r","");print $2}')
IMSI=$(echo "$O" | grep -A1 -i $FW | tail -1)
IMEI=$(echo "$O" | grep -A4 -i $FAMILY | tail -1)
# get signal info
TECH=$(echo "$O" | awk -F[,\ ] '/^\+CNSMOD/ {print $3}')
case "$TECH" in
1*) MODE="GSM";;
2*) MODE="GPRS";;
3*) MODE="EDGE";;
4*) MODE="UMTS";;
5*) MODE="HSDPA";;
6*) MODE="HSUPA";;
7*) MODE="HSPA";;
8*) MODE="LTE";;
*) MODE="--";;
esac
case "$TECH" in
8*)
EARFCN=$(echo "$O" | awk -F[,\ ] '/^\+CPSI/ {print $9}')
CSQ_RSSI=$(echo "$O" | awk -F[,\ ] '/^\+CPSI/ {printf "%.0f\n", $14/10}')
RSRP=$(echo "$O" | awk -F[,\ ] '/^\+CPSI/ {printf "%.0f\n", $13/10}')
RSRQ=$(echo "$O" | awk -F[,\ ] '/^\+CPSI/ {printf "%.0f\n", $12/10}')
SINR=$(echo "$O" | awk -F[,\ ] '/^\+CPSI/ {printf "%.0f\n", ($15*2)-20}')
PCI=$(echo "$O" | awk -F[,\ ] '/^\+CPSI/ {print $7}')
LAC=$(echo "$O" | awk -F [,] '/\+CEREG/{print $3}')
CID=$(echo "$O" | awk -F [,] '/\+CEREG/{print $4}')
BWDL=$(echo "$O" |awk -F[,\ ] '/^\+CPSI/ {print $10}')
BWUL=$(echo "$O" |awk -F[,\ ] '/^\+CPSI/ {print $11}')
ENBx=$(echo $CID | sed -e 's/..$//')
CELL=$(printf %d 0x${CID: -2})
ENBID=$(printf %d 0x$ENBx)
LTE_CA=$(echo "$O" | grep -i CA_Scell | wc -l)
if [ $LTE_CA -gt 0 ]; then
. /usr/share/modeminfo/scripts/ch_to_band
LTE_CA=1
SCH=$(echo "$O" | awk -F[:,] '/CA_Scell/{print $3}')
SBW=$(echo "$O" | awk -F[:,] '/CA_Scell/{print $6}')
for ch in $SCH; do
ch_to_band $ch
SCC="$SCC+$SC"
done
for bwc in $SBW; do
case $bwc in
1) BWCx=3 ;;
2) BWCx=5 ;;
3) BWCx=10 ;;
4) BWCx=15 ;;
5) BWCx=20 ;;
esac
BWCA=$(($BWCA+$BWCx))
done
case $BWDL in
1) BWDx=3 ;;
2) BWDx=5 ;;
3) BWDx=10 ;;
4) BWDx=15 ;;
5) BWDx=20 ;;
esac
BWCA=$((BWDx+$BWCA))
fi
;;
4*|5*|6*|7*)
EARFCN=$(echo "$O" | awk -F[,] '/^\+CPSI/ {print $8}')
ECIO=$(echo "$O" | awk -F[,] '/^\+CPSI/ {printf"%.0f\n", $10}')
SINR="-"$ECIO
LAC=$(echo "$O" | awk -F [,] '/\+CEREG/{print $3}')
CID=$(echo "$O" | awk -F [,] '/\+CEREG/{print $4}')
;;
1*|2*|3*)
EARFCN=$(echo "$O" | awk -F[,\ ] '/^\+CPSI/ {print $7}')
LAC=$(echo "$O" | awk -F [,] '/\+CREG/{print $3}')
CID=$(echo "$O" | awk -F [,] '/\+CREG/{print $4}')
;;
esac
LAC_NUM=$(printf %d 0x$LAC)
CID_NUM=$(printf %d 0x$CID)
CHIPTEMP=$(echo "$O" | awk -F[,\ ] '/^\+CPMUTEMP/ {print $2}')
if [ $(uci -q get modeminfo.@modeminfo[0].decimail) -eq 1 ]; then
LAC=$LAC_NUM
CID=$CID_NUM
fi
}

@ -0,0 +1,7 @@
ATE0
AT+COPS=3,2; +COPS?
AT+CREG=2; +CREG?
AT+CGREG=2; +CGREG?
AT+CEREG=2; +CEREG?; +CSQ
AT+CNSMOD?; +CPSI?; +CMGRMI=4; +CPMUTEMP
AT+CGMI; +CGMM; +CGMR; +CIMI; +ICCID; +CGSN

@ -0,0 +1,56 @@
function modem_data(){
generic_data
DATA=$(echo "$O" | grep -Ev '^$|^OK' | sort)
MANUF=$(echo "$DATA" | awk 'c&&! --c;/ICCID/{c=2}')
MODEL=$(echo "$DATA" | awk 'c&&! --c;/ICCID/{c=1}')
FW=$(echo "$DATA" | awk 'c&&! --c;/ZRSSI/{c=3}')
DEVICE="$MANUF $MODEL"
TECH=$(echo "$DATA" | awk -F [,] '/\+COPS/{print $NF}')
ICCID=$(echo "$DATA" | awk '/ICCID:/{print $2}')
IMSI=$(echo "$DATA" | awk 'c&&! --c;/ZRSSI/{c=1}')
IMEI=$(echo "$DATA" | awk 'c&&! --c;/ZRSSI/{c=2}')
case $TECH in
0|1) MODE=GSM ;;
2) MODE=WCDMA ;;
3) MODE=EDGE ;;
4) MODE=HSDPA ;;
5) MODE=HSUPA ;;
6) MODE=HSDPA,HSUPA ;;
7) MODE=LTE ;;
8) MODE=DC-HSPA+ ;;
esac
case $TECH in
7)
PCI=$(echo "$DATA" | awk -F [:,] '/\+ZCELLINFO/{print $3}')
EARFCN=$(echo "$DATA" | awk -F [:,] '/\+ZCELLINFO/{print $5}')
LAC=$(echo "$DATA" | awk -F [:,] '/\+CEREG/{gsub("\"","");print $4}')
CID=$(echo "$DATA" | awk -F [:,] '/\+CEREG/{gsub("\"","");print $6}')
ENBx=$(echo $CID | sed -e 's/..$//')
ENBID=$(printf %d 0x$ENBx)
CELL=$(printf %d 0x${CID: -2})
CSQ_RSSI=$(echo "$DATA" | awk -F [:,] '/\+ZRSSI/{print $4}')
RSRQ=$(echo "$DATA" | awk -F [:,] '/\+ZRSSI/{print $3}')
RSRP=$(echo "$DATA" | awk -F [:,] '/\+ZRSSI/{print $2}')
SINR=$(echo "$DATA" | awk -F [:,] '/\+ZRSSI/{printf "%.0f\n", $5}')
;;
2|4|5|6|8)
LAC=$(echo "$DATA" | awk -F [:,] '/\+CGREG/{gsub("\"","");print $4}')
CID=$(echo "$DATA" | awk -F [:,] '/\+CGREG/{gsub("\"","");print $5}')
EARFCN=$(echo "$DATA" | awk -F [:,] '/\+ZCELLINFO/{print $4}')
SINR=$(echo "$DATA" | awk -F [:,] '/\+ZRSSI/{printf "%.0f\n", $3}')
;;
0|1|3)
CSQ_RSSI=$(echo "$DATA" | awk -F [:,] '/\+ZRSSI/{print $2}')
LAC=$(echo "$DATA" | awk -F [:,] '/\+CGREG/{gsub("\"","");print $4}')
CID=$(echo "$DATA" | awk -F [:,] '/\+CGREG/{gsub("\"","");print $5}')
EARFCN=$(echo "$DATA" | awk -F [:,] '/\+ZCELLINFO/{print $4}')
;;
esac
if [ $(uci -q get modeminfo.@modeminfo[0].decimail) -eq 1 ]; then
LAC=$(printf %d 0x$LAC)
CID=$(printf %d 0x$CID)
fi
}

@ -0,0 +1,7 @@
ATE0
AT+COPS=3,2; +COPS?
AT+CREG=2; +CREG?
AT+CGREG=2; +CGREG?
AT+CEREG=2; +CEREG?
AT+CSQ; +ZPAS?; +ZRSSI; +ZCELLINFO?
AT+CGMI; +CGMM; +CGMR; +CIMI; +ICCID; +CGSN

@ -0,0 +1,47 @@
ch_to_band(){
case $MODE in
LTE*)
if [ $1 -ge 0 ] && [ $1 -le 599 ]; then
SC=1
elif [ $1 -ge 600 ] && [ $1 -le 1199 ]; then
SC=2
elif [ $1 -ge 1200 ] && [ $1 -le 1949 ]; then
SC=3
elif [ $1 -ge 1950 ] && [ $1 -le 2399 ]; then
SC=4
elif [ $1 -ge 2400 ] && [ $1 -le 2469 ]; then
SC=5
elif [ $1 -ge 2750 ] && [ $1 -le 3449 ]; then
SC=7
elif [ $1 -ge 3450 ] && [ $1 -le 3799 ]; then
SC=8
elif [ $1 -ge 6150 ] && [ $1 -le 6449 ]; then
SC=20
elif [ $1 -ge 9210 ] && [ $1 -le 9659 ]; then
SC=28
elif [ $1 -ge 9870 ] && [ $1 -le 9919 ]; then
SC=31
elif [ $1 -ge 37750 ] && [ $1 -le 38249 ]; then
SC=38
elif [ $1 -ge 38650 ] && [ $1 -le 39649 ]; then
SC=40
else
SC=0
fi
;;
*)
if [ $1 -ge 1 ] && [ $1 -le 124 ]; then
SC=GSM900
elif [ $1 -ge 512 ] && [ $1 -le 885 ]; then
SC=DCS1800
elif [ $1 -ge 955 ] && [ $1 -le 1023 ]; then
SC=DCS900
elif [ $1 -ge 2937 ] && [ $1 -le 3088 ]; then
SC=UMTS900
elif [ $1 -ge 10562 ] && [ $1 -le 10838 ]; then
SC=IMT2100
fi
;;
esac
}

@ -0,0 +1,3 @@
ATE0;
AT+CGMI; ATI5
ATI5

@ -0,0 +1,152 @@
# (c) 2010-2016 Cezary Jackiewicz <cezary@eko.one.pl>
# (c) 2020-2022 modified by Konstantine Shevlyakov <shevlakov@132lan.ru>
# (c) 2021 modified by Vladislav Kadulin <spanky@yandex.ru>
RES="/usr/share/modeminfo"
#GSCRIPT="$RES/scripts/${FAMILY}.txt"
function get_device_info() {
DEVPORT=$(uci -q get modeminfo.@modeminfo[0].device)
case $DEVPORT in
*tty*) continue ;;
*) get_port ;;
esac
modem_family
GSCRIPT="$RES/scripts/${FAMILY}.at"
O=$(atinout $GSCRIPT $DEVPORT - |grep -v '^$')
}
function get_port() {
devices="$(ls /dev/ttyUSB* /dev/ttyACM* /dev/ttyHS* 2>/dev/null | sort -r)"
for d in $devices; do
DEVPORT=$d gcom -s $RES/scripts/probeport.gcom > /dev/null 2>&1
if [ $? = 0 ]; then
uci set modeminfo.@modeminfo[0].device="$d"
uci commit modeminfo
break
fi
done
DEVPORT=$(uci -q get modeminfo.@modeminfo[0].device)
O=$(atinout $GSCRIPT $DEVPORT - |grep -v '^$')
}
function modem_family() {
if [ ! -f /tmp/modemdevice ]; then
F=$(atinout $RES/scripts/family.at $DEVPORT -)
if (echo ${F} | grep -i que >/dev/null); then
FAMILY=QUECTEL
elif (echo ${F} | grep -i sie >/dev/null); then
FAMILY=SIERRA
elif (echo ${F} | grep -i dell >/dev/null); then
FAMILY=DELL
elif (echo ${F} | grep -i xmm >/dev/null); then
FAMILY=INTEL
elif (echo ${F} | grep -i sim >/dev/null); then
FAMILY=SIMCOM
elif (echo ${F} | grep -i fib >/dev/null); then
FAMILY=FIBOCOM
elif (echo ${F} | grep -i qua >/dev/null); then
FAMILY=QUALCOMM
elif (echo ${F} | grep -i hua >/dev/null); then
FAMILY=HUAWEI
elif (echo ${F} | grep -i gos >/dev/null); then
FAMILY=GOSUN
elif (echo ${F} | grep -i zte >/dev/null); then
FAMILY=ZTE
else
FAMILY=GENERIC
fi
echo $FAMILY > /tmp/modemdevice
else
FAMILY=$(cat /tmp/modemdevice)
fi
}
# get CSQ
function get_csq(){
CSQ=$(echo "$O" | awk -F[,\ ] '/^\+CSQ/ {print $2}')
[ "x$CSQ" = "x" ] && CSQ=-1
if [ $CSQ -ge 0 -a $CSQ -le 31 ]; then
CSQ_PER=$(($CSQ * 100/31))
CSQ_COL="red"
[ $CSQ -ge 10 ] && CSQ_COL="red"
[ $CSQ -ge 15 ] && CSQ_COL="orange"
[ $CSQ -ge 20 ] && CSQ_COL="green"
CSQ_RSSI=$((2 * CSQ - 113))
else
CSQ_PER="0"
CSQ_COL="black"
fi
}
# Get MCC or MNC
function get_cops() {
# COPS
COPS_NUM=$(echo "$O" | awk -F[\"] '/^\+COPS: .,2/ {print $2}')
if [ "x$COPS_NUM" != "x" ]; then
COPS_MCC=${COPS_NUM:0:3}
COPS_MNC=${COPS_NUM:3:3}
COPS=$(awk -F[\;] '/'$COPS_NUM'/ {print $2}' $RES/mccmnc.dat)
if [ "x$COPS" = "x" ]; then
COPS="$COPS_MCC $COPS_MNC"
fi
fi
}
# Get Registration data
function get_reg_data(){
for CREG in "+CREG" "+CGREG" "+CEREG"; do
REGST=$(echo "$O" | awk -F[,] '/\'$CREG'/ {print $2}')
if [ "$REGST" ]; then
break
fi
done
}
function generic_data(){
TECH=$(echo "$O" | awk -F[,] '/^\+COPS/ {print $4}')
case "$TECH" in
2*) MODE="UMTS";;
0*|3*) MODE="EDGE";;
4*) MODE="HSDPA";;
5*) MODE="HSUPA";;
6*) MODE="HSPA";;
7*) MODE="LTE";;
*) MODE="--";;
esac
}
# name device via mmcli utility
mmcli_name(){
MMCLI=$(uci -q get modeminfo.@modeminfo[0].mmcli_name)
if [ "$MMCLI" -eq "1" ]; then
if [ -x /usr/bin/mmcli ]; then
MODEM=$(mmcli -L | awk '{print $1}' | head -1)
if [ $MODEM ]; then
MANUF=$(mmcli -m $MODEM -J | jsonfilter -e '@["modem"].*["manufacturer"]' | awk '{gsub("\r", ""); print $0}')
MODEL=$(mmcli -m $MODEM -J | jsonfilter -e '@["modem"].*["model"]' | awk '{gsub("\r", ""); print $0}')
if [ -n "$(echo "$MODEL" | grep "${MANUF}")" ]; then
DEVICE="$MODEL"
else
DEVICE="$MANUF $MODEL"
fi
fi
fi
fi
}
function get_data_in(){
modem_family
get_reg_data
get_cops
get_csq
if [ -f "$RES/scripts/${FAMILY}" ]; then
. $RES/scripts/$FAMILY
modem_data
else
generic_data
fi
mmcli_name
}

@ -0,0 +1,14 @@
let $d = $env("DEVPORT")
if $d = "" goto timeout
open com $d
set com 57600n81
set senddelay 0.05
waitquiet 2 0.5
send "AT^m"
waitfor 2 "OK"
if % = -1 goto timeout
exit 0
:timeout
exit 1
Loading…
Cancel
Save