while [ $# -gt 0 ]; do
case "${1}" in
--timeout=*)
- timeout=$(cli_get_val ${1})
+ timeout=$(cli_get_val "${1}")
;;
--answer=*)
- answer=$(cli_get_val ${1})
+ answer=$(cli_get_val "${1}")
;;
--quiet)
quiet="true"
}
modem_sim_locked() {
- modem_sim_unlocked $@ && return ${EXIT_FALSE} || return ${EXIT_TRUE}
+ modem_sim_unlocked "$@" && return ${EXIT_FALSE} || return ${EXIT_TRUE}
}
modem_sim_unlock() {
modem_get_device_imei ${device} &>/dev/null
}
+modem_mobile_network_status() {
+ local device="${1}"
+ assert isset device
+
+ local ident="${2}"
+ isset ident || ident=1
+
+ cli_headline "${ident}" "Network status"
+
+ modem_sim_status ${device} &>/dev/null
+ local sim_status_code=$?
+
+ local sim_status="unknown"
+ case "${sim_status_code}" in
+ ${EXIT_SIM_READY})
+ sim_status="SIM ready"
+ ;;
+ ${EXIT_SIM_PIN})
+ sim_status="PIN locked"
+ ;;
+ ${EXIT_SIM_PUK})
+ sim_status="PUK locked"
+ ;;
+ esac
+ cli_print_fmt1 "${ident}" "SIM status" "${sim_status}"
+
+ if [ ${sim_status_code} -eq ${EXIT_SIM_READY} ]; then
+ cli_print_fmt1 "${ident}" "Network Registration" \
+ "$(modem_get_network_registration ${device})"
+ cli_print_fmt1 "${ident}" "Operator" \
+ "$(modem_get_network_operator ${device})"
+ cli_print_fmt1 "${ident}" "Mode" \
+ "$(modem_get_network_mode ${device})"
+ cli_print_fmt1 "${ident}" "IMSI" \
+ "$(modem_get_sim_imsi ${device})"
+ cli_print_fmt1 "${ident}" "Signal quality" \
+ "$(modem_get_signal_quality ${device}) dBm"
+
+ local ber=$(modem_get_bit_error_rate ${device})
+ isset ber || ber="unknown"
+ cli_print_fmt1 "${ident}" "Bit Error Rate" "${ber}"
+ fi
+
+ return ${EXIT_OK}
+}
+
# Exit codes of the network registration function.
EXIT_REG_REGISTERED_TO_HOME_NETWORK=0
EXIT_REG_NOT_REGISTERED_NOT_SEARCHING=1
case "${output}" in
*,*)
- local rssi=${output%,*}
+ local asu=${output%,*}
local ber=${output#*,}
print "${!argument}"
return ${EXIT_ERROR}
}
+__modem_rssi_to_dbm() {
+ local rssi="${1}"
+
+ # 99 indicates unknown signal strength
+ [ ${rssi} -eq 99 ] && return ${EXIT_UNKNOWN}
+
+ print "$(( ${rssi} * 2 - 113 ))"
+ return ${EXIT_OK}
+}
+
+__modem_rscp_to_dbm() {
+ local rscp="${1}"
+
+ # 255 indicates unknown signal strength
+ [ ${rscp} -eq 255 ] && return ${EXIT_UNKNOWN}
+
+ print "$(( ${rscp} - 116 ))"
+ return ${EXIT_OK}
+}
+
+__modem_rsrp_to_dbm() {
+ local rsrp="${1}"
+
+ case "${rsrp}" in
+ 0)
+ print "< -140"
+ ;;
+ 97)
+ print "> -44"
+ ;;
+ *)
+ # This is only an approximation since RSRP references
+ # to a range of +/-1dbm
+ print "$(( ${rsrp} - 141 ))"
+ ;;
+ esac
+
+ return ${EXIT_OK}
+}
+
modem_get_signal_quality() {
local device=${1}
assert isset device
- local rssi
- rssi=$(__modem_get_signal_quality ${device} rssi)
+ # Arbritrary Strength Unit
+ local asu
+ asu=$(__modem_get_signal_quality ${device} asu)
assert_check_retval $?
- isset rssi || return ${EXIT_ERROR}
+ isset asu || return ${EXIT_ERROR}
- # 99 indicates an unknown signal strength.
- [ ${rssi} -eq 99 ] && return ${EXIT_UNKNOWN}
+ local network_mode="$(modem_get_network_mode ${device} &>/dev/null; echo $?)"
- local dbm=$(( ${rssi} * 2 ))
- dbm=$(( ${dbm} - 113 ))
+ local ret
+ case "${network_mode}" in
+ # GSM
+ ${EXIT_OPMODE_GSM}|${EXIT_OPMODE_COMPACTGSM}|${GSM_WITH_EGPRS})
+ __modem_rssi_to_dbm "${asu}"
+ ret=${?}
+ ;;
- print "%d" "${dbm}"
- return ${EXIT_OK}
+ # UMTS
+ ${EXIT_OPMODE_UMTS}|${EXIT_OPMODE_UMTS_WITH_HSDPA}|${EXIT_OPMODE_UMTS_WITH_HSUPA}|${EXIT_OPMODE_UMTS_WITH_HSDPA_AND_HSUPA})
+ __modem_rscp_to_dbm "${asu}"
+ ret=${?}
+ ;;
+
+ # LTE
+ ${EXIT_OPMODE_LTE})
+ __modem_rsrp_to_dbm "${asu}"
+ ret=${?}
+ ;;
+
+ # unknown
+ *)
+ ret=${EXIT_ERROR}
+ ;;
+ esac
+
+ return ${ret}
}
modem_get_bit_error_rate() {