Fix USSD D-Bus property extraction and session status parsing
This commit is contained in:
@@ -21,7 +21,7 @@ dial_number() {
|
|||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
mm_state="$(mmcli -m any -K 2>/dev/null | awk -F': ' '$1 == "modem.generic.state" {print $2; exit}')"
|
mm_state="$(mmcli -m any -K 2>/dev/null | awk -F':[[:space:]]*' '{gsub(/[[:space:]]+$/, "", $1); if ($1 == "modem.generic.state") {print $2; exit}}')"
|
||||||
if [ "$mm_state" = "disabled" ] || [ -z "$mm_state" ]; then
|
if [ "$mm_state" = "disabled" ] || [ -z "$mm_state" ]; then
|
||||||
mmcli -m any -e >/dev/null 2>&1 || true
|
mmcli -m any -e >/dev/null 2>&1 || true
|
||||||
mmcli -m any --3gpp-register-home >/dev/null 2>&1 || true
|
mmcli -m any --3gpp-register-home >/dev/null 2>&1 || true
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@@ -1015,24 +1015,28 @@ case "$cmd" in
|
|||||||
echo "ERROR: Empty USSD code"
|
echo "ERROR: Empty USSD code"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
mm_state="$(mmcli -m any -K 2>/dev/null | awk -F': ' '$1 == "modem.generic.state" {print $2; exit}' || true)"
|
mm_state="$(mmcli -m any -K 2>/dev/null | awk -F':[[:space:]]*' '{gsub(/[[:space:]]+$/, "", $1); if ($1 == "modem.generic.state") {print $2; exit}}' || true)"
|
||||||
if [ "$mm_state" = "disabled" ] || [ -z "$mm_state" ]; then
|
if [ "$mm_state" = "disabled" ] || [ -z "$mm_state" ]; then
|
||||||
mmcli -m any -e >/dev/null 2>&1 || true
|
mmcli -m any -e >/dev/null 2>&1 || true
|
||||||
sleep 1
|
sleep 1
|
||||||
fi
|
fi
|
||||||
modem_dbus_path="$(mmcli -m any -K 2>/dev/null | awk -F': ' '$1 == "modem.dbus-path" {print $2; exit}' || true)"
|
modem_dbus_path="$(mmcli -m any -K 2>/dev/null | awk -F':[[:space:]]*' '{gsub(/[[:space:]]+$/, "", $1); if ($1 == "modem.dbus-path") {print $2; exit}}' || true)"
|
||||||
|
[ -z "$modem_dbus_path" ] && modem_dbus_path="/org/freedesktop/ModemManager1/Modem/0"
|
||||||
get_ussd_prop() {
|
get_ussd_prop() {
|
||||||
prop_name="$1"
|
prop_name="$1"
|
||||||
if [ -n "$modem_dbus_path" ] && command -v busctl >/dev/null 2>&1 && command -v jq >/dev/null 2>&1; then
|
if [ -n "$modem_dbus_path" ] && command -v busctl >/dev/null 2>&1 && command -v jq >/dev/null 2>&1; then
|
||||||
busctl --json=short call org.freedesktop.ModemManager1 "$modem_dbus_path" \
|
busctl -j get-property org.freedesktop.ModemManager1 "$modem_dbus_path" \
|
||||||
org.freedesktop.DBus.Properties Get ss \
|
|
||||||
org.freedesktop.ModemManager1.Modem.Modem3gpp.Ussd "$prop_name" 2>/dev/null | \
|
org.freedesktop.ModemManager1.Modem.Modem3gpp.Ussd "$prop_name" 2>/dev/null | \
|
||||||
jq -r '.data[].data // empty' 2>/dev/null || true
|
jq -r '.data // empty' 2>/dev/null || true
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
get_ussd_state() {
|
||||||
|
mmcli -m any --3gpp-ussd-status -K 2>/dev/null | \
|
||||||
|
awk -F':[[:space:]]*' '{gsub(/[[:space:]]+$/, "", $1); if ($1 == "modem.3gpp.ussd.status" || $1 == "modem.3gpp.ussd.state") {print $2; exit}}' || true
|
||||||
|
}
|
||||||
prev_notif="$(get_ussd_prop NetworkNotification)"
|
prev_notif="$(get_ussd_prop NetworkNotification)"
|
||||||
prev_req="$(get_ussd_prop NetworkRequest)"
|
prev_req="$(get_ussd_prop NetworkRequest)"
|
||||||
ussd_st="$(mmcli -m any -K 2>/dev/null | awk -F': ' '$1 == "modem.3gpp.ussd.status" || $1 == "modem.3gpp.ussd.state" {print $2; exit}' || true)"
|
ussd_st="$(get_ussd_state)"
|
||||||
if [ "$ussd_mode" = "respond" ] && [ "$ussd_st" != "user-response" ]; then
|
if [ "$ussd_mode" = "respond" ] && [ "$ussd_st" != "user-response" ]; then
|
||||||
case "$ussd_code" in
|
case "$ussd_code" in
|
||||||
\**\#|\#*\#)
|
\**\#|\#*\#)
|
||||||
@@ -1040,6 +1044,21 @@ case "$cmd" in
|
|||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
|
ev_file="/tmp/ussd_dbus_$$.log"
|
||||||
|
rm -f "$ev_file"
|
||||||
|
if command -v dbus-monitor >/dev/null 2>&1; then
|
||||||
|
dbus-monitor --system "interface='org.freedesktop.DBus.Properties',member='PropertiesChanged',arg0='org.freedesktop.ModemManager1.Modem.Modem3gpp.Ussd'" >"$ev_file" 2>/dev/null &
|
||||||
|
ev_pid=$!
|
||||||
|
else
|
||||||
|
ev_pid=""
|
||||||
|
fi
|
||||||
|
cleanup_ev() {
|
||||||
|
if [ -n "${ev_pid:-}" ]; then
|
||||||
|
kill "$ev_pid" 2>/dev/null || true
|
||||||
|
wait "$ev_pid" 2>/dev/null || true
|
||||||
|
fi
|
||||||
|
rm -f "$ev_file"
|
||||||
|
}
|
||||||
mm_rc=0
|
mm_rc=0
|
||||||
mm_out=""
|
mm_out=""
|
||||||
if [ "$ussd_mode" = "respond" ]; then
|
if [ "$ussd_mode" = "respond" ]; then
|
||||||
@@ -1057,30 +1076,35 @@ case "$cmd" in
|
|||||||
-e "1s/^USSD response sent; new reply from network: '//" \
|
-e "1s/^USSD response sent; new reply from network: '//" \
|
||||||
-e "\$s/'$//")"
|
-e "\$s/'$//")"
|
||||||
if [ -n "$reply" ]; then
|
if [ -n "$reply" ]; then
|
||||||
|
cleanup_ev
|
||||||
printf "%s\n" "$reply"
|
printf "%s\n" "$reply"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
# Check if the USSD response arrived asynchronously via D-Bus properties
|
# Check if the USSD response arrived asynchronously via D-Bus properties
|
||||||
w=0
|
w=0
|
||||||
while [ "$w" -lt 25 ]; do
|
while [ "$w" -lt 15 ]; do
|
||||||
cur_req="$(get_ussd_prop NetworkRequest)"
|
cur_req="$(get_ussd_prop NetworkRequest)"
|
||||||
cur_notif="$(get_ussd_prop NetworkNotification)"
|
cur_notif="$(get_ussd_prop NetworkNotification)"
|
||||||
if [ -n "$cur_req" ] && [ "$cur_req" != "$prev_req" ]; then
|
cur_st="$(get_ussd_state)"
|
||||||
|
if [ -n "$cur_req" ] && { [ "$cur_req" != "$prev_req" ] || [ "$cur_st" = "user-response" ] || grep -q "NetworkRequest" "$ev_file" 2>/dev/null; }; then
|
||||||
|
cleanup_ev
|
||||||
printf "%s\n" "$cur_req"
|
printf "%s\n" "$cur_req"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
if [ -n "$cur_notif" ] && [ "$cur_notif" != "$prev_notif" ]; then
|
if [ -n "$cur_notif" ] && { [ "$cur_notif" != "$prev_notif" ] || grep -q "NetworkNotification" "$ev_file" 2>/dev/null || printf "%s" "$mm_out" | grep -q "USSD terminated by network"; }; then
|
||||||
|
cleanup_ev
|
||||||
printf "%s\n" "$cur_notif"
|
printf "%s\n" "$cur_notif"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
cur_st="$(mmcli -m any -K 2>/dev/null | awk -F': ' '$1 == "modem.3gpp.ussd.status" || $1 == "modem.3gpp.ussd.state" {print $2; exit}' || true)"
|
if [ "$cur_st" != "active" ] && [ "$w" -ge 3 ]; then
|
||||||
if [ "$cur_st" != "active" ] && [ "$w" -ge 8 ]; then
|
|
||||||
if [ -n "$cur_req" ]; then
|
if [ -n "$cur_req" ]; then
|
||||||
|
cleanup_ev
|
||||||
printf "%s\n" "$cur_req"
|
printf "%s\n" "$cur_req"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
if [ -n "$cur_notif" ]; then
|
if [ -n "$cur_notif" ]; then
|
||||||
|
cleanup_ev
|
||||||
printf "%s\n" "$cur_notif"
|
printf "%s\n" "$cur_notif"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
@@ -1089,6 +1113,7 @@ case "$cmd" in
|
|||||||
sleep 0.2
|
sleep 0.2
|
||||||
w=$((w + 1))
|
w=$((w + 1))
|
||||||
done
|
done
|
||||||
|
cleanup_ev
|
||||||
# Fallback to direct AT+CUSD on the active SIM AT port
|
# Fallback to direct AT+CUSD on the active SIM AT port
|
||||||
if [ "$PREFERRED_SIM_SLOT" = "2" ]; then
|
if [ "$PREFERRED_SIM_SLOT" = "2" ]; then
|
||||||
at_candidates="/dev/wwan0at1 /dev/wwan0at0"
|
at_candidates="/dev/wwan0at1 /dev/wwan0at0"
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@@ -1733,7 +1733,7 @@ inline std::string sendModemUssd(const std::string& input,
|
|||||||
|
|
||||||
if (outSessionActive) {
|
if (outSessionActive) {
|
||||||
std::string stOut = runCaptureCmd(
|
std::string stOut = runCaptureCmd(
|
||||||
"mmcli -m any -K 2>/dev/null | grep -E 'modem\\.3gpp\\.ussd\\.(status|state)'");
|
"mmcli -m any --3gpp-ussd-status -K 2>/dev/null | grep -E 'modem\\.3gpp\\.ussd\\.(status|state)'");
|
||||||
if (stOut.find("user-response") != std::string::npos) {
|
if (stOut.find("user-response") != std::string::npos) {
|
||||||
*outSessionActive = true;
|
*outSessionActive = true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user