SPAN_DECLARE(int) fax_modems_v17_v21_rx(void *user_data, const int16_t amp[], int len) { fax_modems_state_t *s; s = (fax_modems_state_t *) user_data; v17_rx(&s->v17_rx, amp, len); fsk_rx(&s->v21_rx, amp, len); if (s->rx_frame_received) { /* We have received something, and the fast modem has not trained. We must be receiving valid V.21 */ span_log(&s->logging, SPAN_LOG_FLOW, "Switching from V.17 + V.21 to V.21 (%.2fdBm0)\n", fsk_rx_signal_power(&s->v21_rx)); s->rx_handler = (span_rx_handler_t *) &fsk_rx; s->rx_user_data = &s->v21_rx; } return 0; }
static int v29_v21_rx(void *user_data, const int16_t amp[], int len) { fax_state_t *t; fax_modems_state_t *s; t = (fax_state_t *) user_data; s = &t->modems; v29_rx(&s->v29_rx, amp, len); if (t->t30.rx_trained) { /* The fast modem has trained, so we no longer need to run the slow one in parallel. */ span_log(&t->logging, SPAN_LOG_FLOW, "Switching from V.29 + V.21 to V.29 (%.2fdBm0)\n", v29_rx_signal_power(&s->v29_rx)); set_rx_handler(t, (span_rx_handler_t *) &v29_rx, (span_rx_fillin_handler_t *) &v29_rx_fillin, &s->v29_rx); } else { fsk_rx(&s->v21_rx, amp, len); if (t->t30.rx_frame_received) { /* We have received something, and the fast modem has not trained. We must be receiving valid V.21 */ span_log(&t->logging, SPAN_LOG_FLOW, "Switching from V.29 + V.21 to V.21 (%.2fdBm0)\n", fsk_rx_signal_power(&s->v21_rx)); set_rx_handler(t, (span_rx_handler_t *) &fsk_rx, (span_rx_fillin_handler_t *) &fsk_rx_fillin, &s->v21_rx); } } return 0; }
SPAN_DECLARE_NONSTD(int) fax_modems_v29_v21_rx(void *user_data, const int16_t amp[], int len) { fax_modems_state_t *s; s = (fax_modems_state_t *) user_data; v29_rx(&s->fast_modems.v29_rx, amp, len); fsk_rx(&s->v21_rx, amp, len); if (s->rx_frame_received) { /* We have received something, and the fast modem has not trained. We must be receiving valid V.21 */ span_log(&s->logging, SPAN_LOG_FLOW, "Switching from V.29 + V.21 to V.21 (%.2fdBm0)\n", fsk_rx_signal_power(&s->v21_rx)); fax_modems_set_rx_handler(s, (span_rx_handler_t) &fsk_rx, &s->v21_rx, (span_rx_fillin_handler_t) &fsk_rx_fillin, &s->v21_rx); } /*endif*/ return 0; }
static void v21_put_bit(void *user_data, int bit) { modem_connect_tones_rx_state_t *s; s = (modem_connect_tones_rx_state_t *) user_data; if (bit < 0) { /* Special conditions. */ switch (bit) { case SIG_STATUS_CARRIER_DOWN: /* Only declare tone off, if we were the one to declare tone on. */ if (s->tone_present == MODEM_CONNECT_TONES_FAX_PREAMBLE) report_tone_state(s, MODEM_CONNECT_TONES_NONE, -99); /* Fall through */ case SIG_STATUS_CARRIER_UP: s->raw_bit_stream = 0; s->num_bits = 0; s->flags_seen = 0; s->framing_ok_announced = FALSE; break; } return; } /* Look for enough FAX V.21 message preamble (back to back HDLC flag octets) to be sure we are really seeing preamble, and declare the signal to be present. Any change from preamble declares the signal to not be present, though it will probably be the body of the messages following the preamble. */ s->raw_bit_stream = (s->raw_bit_stream << 1) | ((bit << 8) & 0x100); s->num_bits++; if ((s->raw_bit_stream & 0x7F00) == 0x7E00) { if ((s->raw_bit_stream & 0x8000)) { /* Hit HDLC abort */ s->flags_seen = 0; } else { /* Hit HDLC flag */ if (s->flags_seen < HDLC_FRAMING_OK_THRESHOLD) { /* Check the flags are back-to-back when testing for valid preamble. This greatly reduces the chances of false preamble detection, and anything which doesn't send them back-to-back is badly broken. */ if (s->num_bits != 8) s->flags_seen = 0; if (++s->flags_seen >= HDLC_FRAMING_OK_THRESHOLD && !s->framing_ok_announced) { report_tone_state(s, MODEM_CONNECT_TONES_FAX_PREAMBLE, lfastrintf(fsk_rx_signal_power(&(s->v21rx)))); s->framing_ok_announced = TRUE; } } } s->num_bits = 0; } else { if (s->flags_seen >= HDLC_FRAMING_OK_THRESHOLD) { if (s->num_bits == 8) { s->framing_ok_announced = FALSE; s->flags_seen = 0; } } } }