diff --git a/libs/spandsp/spandsp/fax-tests.xml b/libs/spandsp/spandsp/fax-tests.xml
index 87574175cd..fcb3b6be5f 100644
--- a/libs/spandsp/spandsp/fax-tests.xml
+++ b/libs/spandsp/spandsp/fax-tests.xml
@@ -233,5 +233,151 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/libs/spandsp/src/t30.c b/libs/spandsp/src/t30.c
index 996d9cfbca..539e760e27 100644
--- a/libs/spandsp/src/t30.c
+++ b/libs/spandsp/src/t30.c
@@ -3865,8 +3865,14 @@ static void process_state_f_doc_and_post_doc_ecm(t30_state_t *s, const uint8_t *
process_rx_pps(s, msg, len);
break;
case T30_CTC:
+ if ((msg[4] & (DISBIT6 | DISBIT5 | DISBIT4 | DISBIT3)) != fallback_sequence[s->current_fallback].dcs_code)
+ {
+ span_log(&s->logging, SPAN_LOG_FLOW, "Modem changed in CTC.\n");
+ if ((s->current_fallback = find_fallback_entry(msg[4] & (DISBIT6 | DISBIT5 | DISBIT4 | DISBIT3))) < 0)
+ span_log(&s->logging, SPAN_LOG_FLOW, "Remote asked for a modem standard we do not support\n");
+ }
s->image_carrier_attempted = false;
- /* T.30 says we change back to long training here */
+ /* T.30 says we change back to long training here, whether or not the far end changed the modem type. */
s->short_train = false;
queue_phase(s, T30_PHASE_D_TX);
set_state(s, T30_STATE_F_DOC_ECM);
diff --git a/libs/spandsp/tests/tsb85_extra_tests.sh b/libs/spandsp/tests/tsb85_extra_tests.sh
index 08d8336eee..7b6a52d46f 100755
--- a/libs/spandsp/tests/tsb85_extra_tests.sh
+++ b/libs/spandsp/tests/tsb85_extra_tests.sh
@@ -28,7 +28,7 @@ run_tsb85_test()
fi
}
-for TEST in PPS-MPS-lost-PPS V17-12000-V29-9600 Phase-D-collision
+for TEST in PPS-MPS-lost-PPS V17-12000-V29-9600 Phase-D-collision Modem-change-at-CTC
do
run_tsb85_test
done