提交 68b8f5f2 authored 作者: Steve Underwood's avatar Steve Underwood

Various tweaks to T.31 modem, prior to getting T.38 really working with T.31

上级 38bf6342
...@@ -203,31 +203,7 @@ static __inline__ void t31_set_at_rx_mode(t31_state_t *s, int new_mode) ...@@ -203,31 +203,7 @@ static __inline__ void t31_set_at_rx_mode(t31_state_t *s, int new_mode)
} }
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/
#if 0 static int front_end_status(t31_state_t *s, int status)
static void monitor_control_messages(t31_state_t *s, const uint8_t *buf, int len)
{
/* Monitor the control messages, at the point where we have the whole message, so we can
see what is happening to things like training success/failure. */
span_log(&s->logging, SPAN_LOG_FLOW, "Monitoring %s\n", t30_frametype(buf[2]));
if (len < 3)
return;
/*endif*/
switch (buf[2])
{
case T30_DCS:
case T30_DCS | 1:
/* We need to know if ECM is about to be used, so we can fake HDLC stuff. */
s->t38_fe.ecm_mode = (len >= 7) && (buf[6] & DISBIT3);
break;
default:
break;
}
/*endswitch*/
}
/*- End of function --------------------------------------------------------*/
#endif
static void front_end_status(t31_state_t *s, int status)
{ {
span_log(&s->logging, SPAN_LOG_FLOW, "Front end status %d\n", status); span_log(&s->logging, SPAN_LOG_FLOW, "Front end status %d\n", status);
switch (status) switch (status)
...@@ -248,6 +224,7 @@ static void front_end_status(t31_state_t *s, int status) ...@@ -248,6 +224,7 @@ static void front_end_status(t31_state_t *s, int status)
{ {
t31_set_at_rx_mode(s, AT_MODE_OFFHOOK_COMMAND); t31_set_at_rx_mode(s, AT_MODE_OFFHOOK_COMMAND);
} }
/*endif*/
break; break;
case FAX_MODEM_CED_TONE: case FAX_MODEM_CED_TONE:
/* Go directly to V.21/HDLC transmit. */ /* Go directly to V.21/HDLC transmit. */
...@@ -265,10 +242,16 @@ static void front_end_status(t31_state_t *s, int status) ...@@ -265,10 +242,16 @@ static void front_end_status(t31_state_t *s, int status)
restart_modem(s, FAX_MODEM_SILENCE_TX); restart_modem(s, FAX_MODEM_SILENCE_TX);
break; break;
} }
/*endswitch*/
break; break;
case T30_FRONT_END_RECEIVE_COMPLETE: case T30_FRONT_END_RECEIVE_COMPLETE:
break; break;
} }
/*endswitch*/
if (s->t38_fe.timed_step == T38_TIMED_STEP_NONE)
return -1;
/*endif*/
return 0;
} }
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/
...@@ -298,14 +281,18 @@ static int extra_bits_in_stuffed_frame(const uint8_t buf[], int len) ...@@ -298,14 +281,18 @@ static int extra_bits_in_stuffed_frame(const uint8_t buf[], int len)
ones = 0; ones = 0;
stuffed++; stuffed++;
} }
/*endif*/
} }
else else
{ {
ones = 0; ones = 0;
} }
/*endif*/
bitstream >>= 1; bitstream >>= 1;
} }
/*endfor*/
} }
/*endfor*/
/* The total length of the frame is: /* The total length of the frame is:
the number of bits in the body the number of bits in the body
+ the number of additional bits in the body due to stuffing + the number of additional bits in the body due to stuffing
...@@ -345,6 +332,7 @@ static int process_rx_indicator(t38_core_state_t *t, void *user_data, int indica ...@@ -345,6 +332,7 @@ static int process_rx_indicator(t38_core_state_t *t, void *user_data, int indica
ignore it. Its harmless. */ ignore it. Its harmless. */
return 0; return 0;
} }
/*endif*/
/* In termination mode we don't care very much about indicators telling us training /* In termination mode we don't care very much about indicators telling us training
is starting. We only care about V.21 preamble starting, for timeout control, and is starting. We only care about V.21 preamble starting, for timeout control, and
the actual data. */ the actual data. */
...@@ -357,6 +345,7 @@ static int process_rx_indicator(t38_core_state_t *t, void *user_data, int indica ...@@ -357,6 +345,7 @@ static int process_rx_indicator(t38_core_state_t *t, void *user_data, int indica
{ {
hdlc_rx_status(s, SIG_STATUS_CARRIER_DOWN); hdlc_rx_status(s, SIG_STATUS_CARRIER_DOWN);
} }
/*endif*/
fe->timeout_rx_samples = 0; fe->timeout_rx_samples = 0;
front_end_status(s, T30_FRONT_END_SIGNAL_ABSENT); front_end_status(s, T30_FRONT_END_SIGNAL_ABSENT);
break; break;
...@@ -403,6 +392,7 @@ static int process_rx_indicator(t38_core_state_t *t, void *user_data, int indica ...@@ -403,6 +392,7 @@ static int process_rx_indicator(t38_core_state_t *t, void *user_data, int indica
front_end_status(s, T30_FRONT_END_SIGNAL_ABSENT); front_end_status(s, T30_FRONT_END_SIGNAL_ABSENT);
break; break;
} }
/*endswitch*/
fe->hdlc_rx.len = 0; fe->hdlc_rx.len = 0;
fe->rx_data_missing = FALSE; fe->rx_data_missing = FALSE;
return 0; return 0;
...@@ -443,6 +433,7 @@ static int process_rx_data(t38_core_state_t *t, void *user_data, int data_type, ...@@ -443,6 +433,7 @@ static int process_rx_data(t38_core_state_t *t, void *user_data, int data_type,
default: default:
break; break;
} }
/*endswitch*/
#endif #endif
switch (field_type) switch (field_type)
{ {
...@@ -491,6 +482,13 @@ static int process_rx_data(t38_core_state_t *t, void *user_data, int data_type, ...@@ -491,6 +482,13 @@ static int process_rx_data(t38_core_state_t *t, void *user_data, int data_type,
if (t->current_rx_data_type != data_type || t->current_rx_field_type != field_type) if (t->current_rx_data_type != data_type || t->current_rx_field_type != field_type)
{ {
span_log(&s->logging, SPAN_LOG_FLOW, "Type %s - CRC OK (%s)\n", (fe->hdlc_rx.len >= 3) ? t30_frametype(fe->hdlc_rx.buf[2]) : "???", (fe->rx_data_missing) ? "missing octets" : "clean"); span_log(&s->logging, SPAN_LOG_FLOW, "Type %s - CRC OK (%s)\n", (fe->hdlc_rx.len >= 3) ? t30_frametype(fe->hdlc_rx.buf[2]) : "???", (fe->rx_data_missing) ? "missing octets" : "clean");
if (fe->hdlc_rx.len >= 3 && (fe->hdlc_rx.buf[2] & 0xFE) == T30_DCS)
{
/* We need to know if ECM is about to be used, so we can fake HDLC stuff. */
fe->ecm_mode = (fe->hdlc_rx.len >= 7 && (fe->hdlc_rx.buf[6] & DISBIT3));
span_log(&s->logging, SPAN_LOG_FLOW, "ECM mode: %d\n", fe->ecm_mode);
}
/*endif*/
crc_itu16_append(fe->hdlc_rx.buf, fe->hdlc_rx.len); crc_itu16_append(fe->hdlc_rx.buf, fe->hdlc_rx.len);
hdlc_accept_frame(s, fe->hdlc_rx.buf, fe->hdlc_rx.len, !fe->rx_data_missing); hdlc_accept_frame(s, fe->hdlc_rx.buf, fe->hdlc_rx.len, !fe->rx_data_missing);
} }
...@@ -527,16 +525,25 @@ static int process_rx_data(t38_core_state_t *t, void *user_data, int data_type, ...@@ -527,16 +525,25 @@ static int process_rx_data(t38_core_state_t *t, void *user_data, int data_type,
/* The sender has incorrectly included data in this message. It is unclear what we should do /* The sender has incorrectly included data in this message. It is unclear what we should do
with it, to maximise tolerance of buggy implementations. */ with it, to maximise tolerance of buggy implementations. */
} }
/*endif*/
/* Some T.38 implementations send multiple T38_FIELD_HDLC_FCS_OK_SIG_END messages, in IFP packets with /* Some T.38 implementations send multiple T38_FIELD_HDLC_FCS_OK_SIG_END messages, in IFP packets with
incrementing sequence numbers, which are actually repeats. They get through to this point because incrementing sequence numbers, which are actually repeats. They get through to this point because
of the incrementing sequence numbers. We need to filter them here in a context sensitive manner. */ of the incrementing sequence numbers. We need to filter them here in a context sensitive manner. */
if (t->current_rx_data_type != data_type || t->current_rx_field_type != field_type) if (t->current_rx_data_type != data_type || t->current_rx_field_type != field_type)
{ {
span_log(&s->logging, SPAN_LOG_FLOW, "Type %s - CRC OK, sig end (%s)\n", (fe->hdlc_rx.len >= 3) ? t30_frametype(fe->hdlc_rx.buf[2]) : "???", (fe->rx_data_missing) ? "missing octets" : "clean"); span_log(&s->logging, SPAN_LOG_FLOW, "Type %s - CRC OK, sig end (%s)\n", (fe->hdlc_rx.len >= 3) ? t30_frametype(fe->hdlc_rx.buf[2]) : "???", (fe->rx_data_missing) ? "missing octets" : "clean");
if (fe->hdlc_rx.len >= 3 && (fe->hdlc_rx.buf[2] & 0xFE) == T30_DCS)
{
/* We need to know if ECM is about to be used, so we can fake HDLC stuff. */
fe->ecm_mode = (fe->hdlc_rx.len >= 7 && (fe->hdlc_rx.buf[6] & DISBIT3));
span_log(&s->logging, SPAN_LOG_FLOW, "ECM mode: %d\n", fe->ecm_mode);
}
/*endif*/
crc_itu16_append(fe->hdlc_rx.buf, fe->hdlc_rx.len); crc_itu16_append(fe->hdlc_rx.buf, fe->hdlc_rx.len);
hdlc_accept_frame(s, fe->hdlc_rx.buf, fe->hdlc_rx.len, !fe->rx_data_missing); hdlc_accept_frame(s, fe->hdlc_rx.buf, fe->hdlc_rx.len, !fe->rx_data_missing);
hdlc_rx_status(s, SIG_STATUS_CARRIER_DOWN); hdlc_rx_status(s, SIG_STATUS_CARRIER_DOWN);
} }
/*endif*/
fe->hdlc_rx.len = 0; fe->hdlc_rx.len = 0;
fe->rx_data_missing = FALSE; fe->rx_data_missing = FALSE;
fe->timeout_rx_samples = 0; fe->timeout_rx_samples = 0;
...@@ -548,6 +555,7 @@ static int process_rx_data(t38_core_state_t *t, void *user_data, int data_type, ...@@ -548,6 +555,7 @@ static int process_rx_data(t38_core_state_t *t, void *user_data, int data_type,
/* The sender has incorrectly included data in this message. We can safely ignore it, as the /* The sender has incorrectly included data in this message. We can safely ignore it, as the
bad FCS means we will throw away the whole message, anyway. */ bad FCS means we will throw away the whole message, anyway. */
} }
/*endif*/
/* Some T.38 implementations send multiple T38_FIELD_HDLC_FCS_BAD_SIG_END messages, in IFP packets with /* Some T.38 implementations send multiple T38_FIELD_HDLC_FCS_BAD_SIG_END messages, in IFP packets with
incrementing sequence numbers, which are actually repeats. They get through to this point because incrementing sequence numbers, which are actually repeats. They get through to this point because
of the incrementing sequence numbers. We need to filter them here in a context sensitive manner. */ of the incrementing sequence numbers. We need to filter them here in a context sensitive manner. */
...@@ -557,6 +565,7 @@ static int process_rx_data(t38_core_state_t *t, void *user_data, int data_type, ...@@ -557,6 +565,7 @@ static int process_rx_data(t38_core_state_t *t, void *user_data, int data_type,
hdlc_accept_frame(s, fe->hdlc_rx.buf, fe->hdlc_rx.len, FALSE); hdlc_accept_frame(s, fe->hdlc_rx.buf, fe->hdlc_rx.len, FALSE);
hdlc_rx_status(s, SIG_STATUS_CARRIER_DOWN); hdlc_rx_status(s, SIG_STATUS_CARRIER_DOWN);
} }
/*endif*/
fe->hdlc_rx.len = 0; fe->hdlc_rx.len = 0;
fe->rx_data_missing = FALSE; fe->rx_data_missing = FALSE;
fe->timeout_rx_samples = 0; fe->timeout_rx_samples = 0;
...@@ -568,6 +577,7 @@ static int process_rx_data(t38_core_state_t *t, void *user_data, int data_type, ...@@ -568,6 +577,7 @@ static int process_rx_data(t38_core_state_t *t, void *user_data, int data_type,
/* The sender has incorrectly included data in this message, but there seems nothing meaningful /* The sender has incorrectly included data in this message, but there seems nothing meaningful
it could be. There could not be an FCS good/bad report beyond this. */ it could be. There could not be an FCS good/bad report beyond this. */
} }
/*endif*/
/* Some T.38 implementations send multiple T38_FIELD_HDLC_SIG_END messages, in IFP packets with /* Some T.38 implementations send multiple T38_FIELD_HDLC_SIG_END messages, in IFP packets with
incrementing sequence numbers, which are actually repeats. They get through to this point because incrementing sequence numbers, which are actually repeats. They get through to this point because
of the incrementing sequence numbers. We need to filter them here in a context sensitive manner. */ of the incrementing sequence numbers. We need to filter them here in a context sensitive manner. */
...@@ -584,6 +594,7 @@ static int process_rx_data(t38_core_state_t *t, void *user_data, int data_type, ...@@ -584,6 +594,7 @@ static int process_rx_data(t38_core_state_t *t, void *user_data, int data_type,
fe->timeout_rx_samples = 0; fe->timeout_rx_samples = 0;
hdlc_rx_status(s, SIG_STATUS_CARRIER_DOWN); hdlc_rx_status(s, SIG_STATUS_CARRIER_DOWN);
} }
/*endif*/
break; break;
case T38_FIELD_T4_NON_ECM_DATA: case T38_FIELD_T4_NON_ECM_DATA:
if (!s->at_state.rx_signal_present) if (!s->at_state.rx_signal_present)
...@@ -591,11 +602,13 @@ static int process_rx_data(t38_core_state_t *t, void *user_data, int data_type, ...@@ -591,11 +602,13 @@ static int process_rx_data(t38_core_state_t *t, void *user_data, int data_type,
non_ecm_rx_status(s, SIG_STATUS_TRAINING_SUCCEEDED); non_ecm_rx_status(s, SIG_STATUS_TRAINING_SUCCEEDED);
s->at_state.rx_signal_present = TRUE; s->at_state.rx_signal_present = TRUE;
} }
/*endif*/
if (len > 0) if (len > 0)
{ {
bit_reverse(buf2, buf, len); bit_reverse(buf2, buf, len);
non_ecm_put(s, buf, len); non_ecm_put(s, buf2, len);
} }
/*endif*/
fe->timeout_rx_samples = fe->samples + ms_to_samples(MID_RX_TIMEOUT); fe->timeout_rx_samples = fe->samples + ms_to_samples(MID_RX_TIMEOUT);
break; break;
case T38_FIELD_T4_NON_ECM_SIG_END: case T38_FIELD_T4_NON_ECM_SIG_END:
...@@ -611,15 +624,18 @@ static int process_rx_data(t38_core_state_t *t, void *user_data, int data_type, ...@@ -611,15 +624,18 @@ static int process_rx_data(t38_core_state_t *t, void *user_data, int data_type,
non_ecm_rx_status(s, SIG_STATUS_TRAINING_SUCCEEDED); non_ecm_rx_status(s, SIG_STATUS_TRAINING_SUCCEEDED);
s->at_state.rx_signal_present = TRUE; s->at_state.rx_signal_present = TRUE;
} }
/*endif*/
bit_reverse(buf2, buf, len); bit_reverse(buf2, buf, len);
non_ecm_put(s, buf, len); non_ecm_put(s, buf2, len);
} }
/*endif*/
/* WORKAROUND: At least some Mediatrix boxes have a bug, where they can send HDLC signal end where /* WORKAROUND: At least some Mediatrix boxes have a bug, where they can send HDLC signal end where
they should send non-ECM signal end. It is possible they also do the opposite. they should send non-ECM signal end. It is possible they also do the opposite.
We need to tolerate this, so we use the generic receive complete We need to tolerate this, so we use the generic receive complete
indication, rather than the specific non-ECM carrier down. */ indication, rather than the specific non-ECM carrier down. */
non_ecm_rx_status(s, SIG_STATUS_CARRIER_DOWN); non_ecm_rx_status(s, SIG_STATUS_CARRIER_DOWN);
} }
/*endif*/
s->at_state.rx_signal_present = FALSE; s->at_state.rx_signal_present = FALSE;
fe->timeout_rx_samples = 0; fe->timeout_rx_samples = 0;
break; break;
...@@ -628,18 +644,21 @@ static int process_rx_data(t38_core_state_t *t, void *user_data, int data_type, ...@@ -628,18 +644,21 @@ static int process_rx_data(t38_core_state_t *t, void *user_data, int data_type,
span_log(&s->logging, SPAN_LOG_FLOW, "CM profile %d - %s\n", buf[0] - '0', t38_cm_profile_to_str(buf[0])); span_log(&s->logging, SPAN_LOG_FLOW, "CM profile %d - %s\n", buf[0] - '0', t38_cm_profile_to_str(buf[0]));
else else
span_log(&s->logging, SPAN_LOG_FLOW, "Bad length for CM message - %d\n", len); span_log(&s->logging, SPAN_LOG_FLOW, "Bad length for CM message - %d\n", len);
/*endif*/
break; break;
case T38_FIELD_JM_MESSAGE: case T38_FIELD_JM_MESSAGE:
if (len >= 2) if (len >= 2)
span_log(&s->logging, SPAN_LOG_FLOW, "JM - %s\n", t38_jm_to_str(buf, len)); span_log(&s->logging, SPAN_LOG_FLOW, "JM - %s\n", t38_jm_to_str(buf, len));
else else
span_log(&s->logging, SPAN_LOG_FLOW, "Bad length for JM message - %d\n", len); span_log(&s->logging, SPAN_LOG_FLOW, "Bad length for JM message - %d\n", len);
/*endif*/
break; break;
case T38_FIELD_CI_MESSAGE: case T38_FIELD_CI_MESSAGE:
if (len >= 1) if (len >= 1)
span_log(&s->logging, SPAN_LOG_FLOW, "CI 0x%X\n", buf[0]); span_log(&s->logging, SPAN_LOG_FLOW, "CI 0x%X\n", buf[0]);
else else
span_log(&s->logging, SPAN_LOG_FLOW, "Bad length for CI message - %d\n", len); span_log(&s->logging, SPAN_LOG_FLOW, "Bad length for CI message - %d\n", len);
/*endif*/
break; break;
case T38_FIELD_V34RATE: case T38_FIELD_V34RATE:
if (len >= 3) if (len >= 3)
...@@ -651,10 +670,12 @@ static int process_rx_data(t38_core_state_t *t, void *user_data, int data_type, ...@@ -651,10 +670,12 @@ static int process_rx_data(t38_core_state_t *t, void *user_data, int data_type,
{ {
span_log(&s->logging, SPAN_LOG_FLOW, "Bad length for V34rate message - %d\n", len); span_log(&s->logging, SPAN_LOG_FLOW, "Bad length for V34rate message - %d\n", len);
} }
/*endif*/
break; break;
default: default:
break; break;
} }
/*endswitch*/
return 0; return 0;
} }
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/
...@@ -670,11 +691,19 @@ static void send_hdlc(void *user_data, const uint8_t *msg, int len) ...@@ -670,11 +691,19 @@ static void send_hdlc(void *user_data, const uint8_t *msg, int len)
} }
else else
{ {
if (len >= 3 && (s->hdlc_tx.buf[2] & 0xFE) == T30_DCS)
{
/* We need to know if ECM is about to be used, so we can fake HDLC stuff. */
s->t38_fe.ecm_mode = (len >= 7 && (s->hdlc_tx.buf[6] & DISBIT3));
span_log(&s->logging, SPAN_LOG_FLOW, "ECM mode: %d\n", s->t38_fe.ecm_mode);
}
/*endif*/
s->t38_fe.hdlc_tx.extra_bits = extra_bits_in_stuffed_frame(msg, len); s->t38_fe.hdlc_tx.extra_bits = extra_bits_in_stuffed_frame(msg, len);
bit_reverse(s->hdlc_tx.buf, msg, len); bit_reverse(s->hdlc_tx.buf, msg, len);
s->hdlc_tx.len = len; s->hdlc_tx.len = len;
s->hdlc_tx.ptr = 0; s->hdlc_tx.ptr = 0;
} }
/*endif*/
} }
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/
...@@ -695,11 +724,13 @@ static void set_octets_per_data_packet(t31_state_t *s, int bit_rate) ...@@ -695,11 +724,13 @@ static void set_octets_per_data_packet(t31_state_t *s, int bit_rate)
/* Make sure we have a positive number (i.e. we didn't truncate to zero). */ /* Make sure we have a positive number (i.e. we didn't truncate to zero). */
if (s->t38_fe.octets_per_data_packet < 1) if (s->t38_fe.octets_per_data_packet < 1)
s->t38_fe.octets_per_data_packet = 1; s->t38_fe.octets_per_data_packet = 1;
/*endif*/
} }
else else
{ {
s->t38_fe.octets_per_data_packet = MAX_OCTETS_PER_UNPACED_CHUNK; s->t38_fe.octets_per_data_packet = MAX_OCTETS_PER_UNPACED_CHUNK;
} }
/*endif*/
} }
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/
...@@ -723,7 +754,9 @@ static int stream_non_ecm(t31_state_t *s) ...@@ -723,7 +754,9 @@ static int stream_non_ecm(t31_state_t *s)
{ {
/* ???????? */ /* ???????? */
} }
/*endif*/
} }
/*endif*/
fe->timed_step = T38_TIMED_STEP_NON_ECM_MODEM_2; fe->timed_step = T38_TIMED_STEP_NON_ECM_MODEM_2;
fe->next_tx_samples = fe->samples; fe->next_tx_samples = fe->samples;
break; break;
...@@ -733,6 +766,7 @@ static int stream_non_ecm(t31_state_t *s) ...@@ -733,6 +766,7 @@ static int stream_non_ecm(t31_state_t *s)
{ {
/* ???????? */ /* ???????? */
} }
/*endif*/
fe->timed_step = T38_TIMED_STEP_NON_ECM_MODEM_3; fe->timed_step = T38_TIMED_STEP_NON_ECM_MODEM_3;
break; break;
case T38_TIMED_STEP_NON_ECM_MODEM_3: case T38_TIMED_STEP_NON_ECM_MODEM_3:
...@@ -744,10 +778,11 @@ static int stream_non_ecm(t31_state_t *s) ...@@ -744,10 +778,11 @@ static int stream_non_ecm(t31_state_t *s)
len = non_ecm_get(s, buf, fe->octets_per_data_packet); len = non_ecm_get(s, buf, fe->octets_per_data_packet);
if (len > 0) if (len > 0)
bit_reverse(buf, buf, len); bit_reverse(buf, buf, len);
/*endif*/
if (len < fe->octets_per_data_packet) if (len < fe->octets_per_data_packet)
{ {
/* That's the end of the image data. */ /* That's the end of the image data. */
if (s->t38_fe.ms_per_tx_chunk) if (fe->ms_per_tx_chunk)
{ {
/* Pad the end of the data with some zeros. If we just stop abruptly /* Pad the end of the data with some zeros. If we just stop abruptly
at the end of the EOLs, some ATAs fail to clean up properly before at the end of the EOLs, some ATAs fail to clean up properly before
...@@ -768,20 +803,24 @@ static int stream_non_ecm(t31_state_t *s) ...@@ -768,20 +803,24 @@ static int stream_non_ecm(t31_state_t *s)
{ {
/* ???????? */ /* ???????? */
} }
/*endif*/
fe->timed_step = T38_TIMED_STEP_NON_ECM_MODEM_5; fe->timed_step = T38_TIMED_STEP_NON_ECM_MODEM_5;
delay = 0; delay = 0;
} }
/*endif*/
} }
/*endif*/
if (t38_core_send_data(&fe->t38, fe->current_tx_data_type, T38_FIELD_T4_NON_ECM_DATA, buf, len, T38_PACKET_CATEGORY_IMAGE_DATA) < 0) if (t38_core_send_data(&fe->t38, fe->current_tx_data_type, T38_FIELD_T4_NON_ECM_DATA, buf, len, T38_PACKET_CATEGORY_IMAGE_DATA) < 0)
{ {
/* ???????? */ /* ???????? */
} }
/*endif*/
delay = bits_to_us(s, 8*len); delay = bits_to_us(s, 8*len);
break; break;
case T38_TIMED_STEP_NON_ECM_MODEM_4: case T38_TIMED_STEP_NON_ECM_MODEM_4:
/* Send padding */ /* Send padding */
len = fe->octets_per_data_packet; len = fe->octets_per_data_packet;
fe->non_ecm_trailer_bytes -= len; fe->non_ecm_trailer_bytes -= fe->octets_per_data_packet;
if (fe->non_ecm_trailer_bytes <= 0) if (fe->non_ecm_trailer_bytes <= 0)
{ {
len += fe->non_ecm_trailer_bytes; len += fe->non_ecm_trailer_bytes;
...@@ -790,20 +829,24 @@ static int stream_non_ecm(t31_state_t *s) ...@@ -790,20 +829,24 @@ static int stream_non_ecm(t31_state_t *s)
{ {
/* ???????? */ /* ???????? */
} }
/*endif*/
fe->timed_step = T38_TIMED_STEP_NON_ECM_MODEM_5; fe->timed_step = T38_TIMED_STEP_NON_ECM_MODEM_5;
/* Allow a bit more time than the data will take to play out, to ensure the far ATA does not /* Allow a bit more time than the data will take to play out, to ensure the far ATA does not
cut things short. */ cut things short. */
delay = bits_to_us(s, 8*len); delay = bits_to_us(s, 8*len);
if (s->t38_fe.ms_per_tx_chunk) if (fe->ms_per_tx_chunk)
delay += 60000; delay += 60000;
/*endif*/
front_end_status(s, T30_FRONT_END_SEND_STEP_COMPLETE); front_end_status(s, T30_FRONT_END_SEND_STEP_COMPLETE);
break; break;
} }
/*endif*/
memset(buf, 0, len); memset(buf, 0, len);
if (t38_core_send_data(&fe->t38, fe->current_tx_data_type, T38_FIELD_T4_NON_ECM_DATA, buf, len, T38_PACKET_CATEGORY_IMAGE_DATA) < 0) if (t38_core_send_data(&fe->t38, fe->current_tx_data_type, T38_FIELD_T4_NON_ECM_DATA, buf, len, T38_PACKET_CATEGORY_IMAGE_DATA) < 0)
{ {
/* ???????? */ /* ???????? */
} }
/*endif*/
delay = bits_to_us(s, 8*len); delay = bits_to_us(s, 8*len);
break; break;
case T38_TIMED_STEP_NON_ECM_MODEM_5: case T38_TIMED_STEP_NON_ECM_MODEM_5:
...@@ -813,10 +856,13 @@ static int stream_non_ecm(t31_state_t *s) ...@@ -813,10 +856,13 @@ static int stream_non_ecm(t31_state_t *s)
{ {
/* ???????? */ /* ???????? */
} }
/*endif*/
fe->timed_step = T38_TIMED_STEP_NONE; fe->timed_step = T38_TIMED_STEP_NONE;
return delay; return delay;
} }
/*endswitch*/
} }
/*endfor*/
return delay; return delay;
} }
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/
...@@ -844,7 +890,9 @@ static int stream_hdlc(t31_state_t *s) ...@@ -844,7 +890,9 @@ static int stream_hdlc(t31_state_t *s)
{ {
/* ???????? */ /* ???????? */
} }
/*endif*/
} }
/*endif*/
fe->timed_step = T38_TIMED_STEP_HDLC_MODEM_2; fe->timed_step = T38_TIMED_STEP_HDLC_MODEM_2;
fe->next_tx_samples = fe->samples + ms_to_samples(75); fe->next_tx_samples = fe->samples + ms_to_samples(75);
break; break;
...@@ -854,6 +902,7 @@ static int stream_hdlc(t31_state_t *s) ...@@ -854,6 +902,7 @@ static int stream_hdlc(t31_state_t *s)
{ {
/* ???????? */ /* ???????? */
} }
/*endif*/
delay += t38_core_send_flags_delay(&fe->t38, fe->next_tx_indicator); delay += t38_core_send_flags_delay(&fe->t38, fe->next_tx_indicator);
at_put_response_code(&s->at_state, AT_RESPONSE_CODE_CONNECT); at_put_response_code(&s->at_state, AT_RESPONSE_CODE_CONNECT);
fe->timed_step = T38_TIMED_STEP_HDLC_MODEM_3; fe->timed_step = T38_TIMED_STEP_HDLC_MODEM_3;
...@@ -866,11 +915,12 @@ static int stream_hdlc(t31_state_t *s) ...@@ -866,11 +915,12 @@ static int stream_hdlc(t31_state_t *s)
delay = MS_PER_TX_CHUNK*1000; delay = MS_PER_TX_CHUNK*1000;
break; break;
} }
/*endif*/
i = s->hdlc_tx.len - s->hdlc_tx.ptr; i = s->hdlc_tx.len - s->hdlc_tx.ptr;
if (fe->octets_per_data_packet >= i) if (fe->octets_per_data_packet >= i)
{ {
/* The last part of an HDLC frame */ /* The last part of an HDLC frame */
if (fe->chunking_modes & T38_CHUNKING_MERGE_FCS_WITH_DATA) if ((fe->chunking_modes & T38_CHUNKING_MERGE_FCS_WITH_DATA))
{ {
/* Copy the data, as we might be about to refill the buffer it is in */ /* Copy the data, as we might be about to refill the buffer it is in */
memcpy(buf, &s->hdlc_tx.buf[s->hdlc_tx.ptr], i); memcpy(buf, &s->hdlc_tx.buf[s->hdlc_tx.ptr], i);
...@@ -883,58 +933,66 @@ static int stream_hdlc(t31_state_t *s) ...@@ -883,58 +933,66 @@ static int stream_hdlc(t31_state_t *s)
s->hdlc_tx.ptr = 0; s->hdlc_tx.ptr = 0;
s->hdlc_tx.len = 0; s->hdlc_tx.len = 0;
front_end_status(s, T30_FRONT_END_SEND_STEP_COMPLETE); front_end_status(s, T30_FRONT_END_SEND_STEP_COMPLETE);
if (s->hdlc_tx.final) if (!s->hdlc_tx.final)
{ {
data_fields[1].field_type = T38_FIELD_HDLC_FCS_OK_SIG_END; data_fields[1].field_type = T38_FIELD_HDLC_FCS_OK;
data_fields[1].field = NULL; data_fields[1].field = NULL;
data_fields[1].field_len = 0; data_fields[1].field_len = 0;
category = (s->t38_fe.current_tx_data_type == T38_DATA_V21) ? T38_PACKET_CATEGORY_CONTROL_DATA_END : T38_PACKET_CATEGORY_IMAGE_DATA_END; category = (fe->current_tx_data_type == T38_DATA_V21) ? T38_PACKET_CATEGORY_CONTROL_DATA : T38_PACKET_CATEGORY_IMAGE_DATA;
if (t38_core_send_data_multi_field(&fe->t38, fe->current_tx_data_type, data_fields, 2, category) < 0) if (t38_core_send_data_multi_field(&fe->t38, fe->current_tx_data_type, data_fields, 2, category) < 0)
{ {
/* ???????? */ /* ???????? */
} }
fe->timed_step = T38_TIMED_STEP_HDLC_MODEM_5; /*endif*/
/* We add a bit of extra time here, as with some implementations fe->timed_step = T38_TIMED_STEP_HDLC_MODEM_3;
the carrier falling too abruptly causes data loss. */
delay = bits_to_us(s, i*8 + fe->hdlc_tx.extra_bits); delay = bits_to_us(s, i*8 + fe->hdlc_tx.extra_bits);
if (s->t38_fe.ms_per_tx_chunk) at_put_response_code(&s->at_state, AT_RESPONSE_CODE_CONNECT);
delay += 100000;
at_put_response_code(&s->at_state, AT_RESPONSE_CODE_OK);
t31_set_at_rx_mode(s, AT_MODE_OFFHOOK_COMMAND);
} }
else else
{ {
data_fields[1].field_type = T38_FIELD_HDLC_FCS_OK; data_fields[1].field_type = T38_FIELD_HDLC_FCS_OK_SIG_END;
data_fields[1].field = NULL; data_fields[1].field = NULL;
data_fields[1].field_len = 0; data_fields[1].field_len = 0;
category = (s->t38_fe.current_tx_data_type == T38_DATA_V21) ? T38_PACKET_CATEGORY_CONTROL_DATA : T38_PACKET_CATEGORY_IMAGE_DATA; category = (fe->current_tx_data_type == T38_DATA_V21) ? T38_PACKET_CATEGORY_CONTROL_DATA_END : T38_PACKET_CATEGORY_IMAGE_DATA_END;
if (t38_core_send_data_multi_field(&fe->t38, fe->current_tx_data_type, data_fields, 2, category) < 0) if (t38_core_send_data_multi_field(&fe->t38, fe->current_tx_data_type, data_fields, 2, category) < 0)
{ {
/* ???????? */ /* ???????? */
} }
fe->timed_step = T38_TIMED_STEP_HDLC_MODEM_3; /*endif*/
fe->timed_step = T38_TIMED_STEP_HDLC_MODEM_5;
/* We add a bit of extra time here, as with some implementations
the carrier falling too abruptly causes data loss. */
delay = bits_to_us(s, i*8 + fe->hdlc_tx.extra_bits); delay = bits_to_us(s, i*8 + fe->hdlc_tx.extra_bits);
at_put_response_code(&s->at_state, AT_RESPONSE_CODE_CONNECT); if (fe->ms_per_tx_chunk)
delay += 100000;
/*endif*/
at_put_response_code(&s->at_state, AT_RESPONSE_CODE_OK);
t31_set_at_rx_mode(s, AT_MODE_OFFHOOK_COMMAND);
} }
/*endif*/
break; break;
} }
category = (s->t38_fe.current_tx_data_type == T38_DATA_V21) ? T38_PACKET_CATEGORY_CONTROL_DATA : T38_PACKET_CATEGORY_IMAGE_DATA; /*endif*/
category = (fe->current_tx_data_type == T38_DATA_V21) ? T38_PACKET_CATEGORY_CONTROL_DATA : T38_PACKET_CATEGORY_IMAGE_DATA;
if (t38_core_send_data(&fe->t38, fe->current_tx_data_type, T38_FIELD_HDLC_DATA, &s->hdlc_tx.buf[s->hdlc_tx.ptr], i, category) < 0) if (t38_core_send_data(&fe->t38, fe->current_tx_data_type, T38_FIELD_HDLC_DATA, &s->hdlc_tx.buf[s->hdlc_tx.ptr], i, category) < 0)
{ {
/* ???????? */ /* ???????? */
} }
/*endif*/
fe->timed_step = T38_TIMED_STEP_HDLC_MODEM_4; fe->timed_step = T38_TIMED_STEP_HDLC_MODEM_4;
} }
else else
{ {
i = fe->octets_per_data_packet; i = fe->octets_per_data_packet;
category = (s->t38_fe.current_tx_data_type == T38_DATA_V21) ? T38_PACKET_CATEGORY_CONTROL_DATA : T38_PACKET_CATEGORY_IMAGE_DATA; category = (fe->current_tx_data_type == T38_DATA_V21) ? T38_PACKET_CATEGORY_CONTROL_DATA : T38_PACKET_CATEGORY_IMAGE_DATA;
if (t38_core_send_data(&fe->t38, fe->current_tx_data_type, T38_FIELD_HDLC_DATA, &s->hdlc_tx.buf[s->hdlc_tx.ptr], i, category) < 0) if (t38_core_send_data(&fe->t38, fe->current_tx_data_type, T38_FIELD_HDLC_DATA, &s->hdlc_tx.buf[s->hdlc_tx.ptr], i, category) < 0)
{ {
/* ???????? */ /* ???????? */
} }
/*endif*/
s->hdlc_tx.ptr += i; s->hdlc_tx.ptr += i;
} }
/*endif*/
delay = bits_to_us(s, i*8); delay = bits_to_us(s, i*8);
break; break;
case T38_TIMED_STEP_HDLC_MODEM_4: case T38_TIMED_STEP_HDLC_MODEM_4:
...@@ -942,56 +1000,67 @@ static int stream_hdlc(t31_state_t *s) ...@@ -942,56 +1000,67 @@ static int stream_hdlc(t31_state_t *s)
previous = fe->current_tx_data_type; previous = fe->current_tx_data_type;
s->hdlc_tx.ptr = 0; s->hdlc_tx.ptr = 0;
s->hdlc_tx.len = 0; s->hdlc_tx.len = 0;
if (s->hdlc_tx.final) if (!s->hdlc_tx.final)
{
/* Finish the current frame off, and prepare for the next one. */
category = (fe->current_tx_data_type == T38_DATA_V21) ? T38_PACKET_CATEGORY_CONTROL_DATA : T38_PACKET_CATEGORY_IMAGE_DATA;
if (t38_core_send_data(&fe->t38, previous, T38_FIELD_HDLC_FCS_OK, NULL, 0, category) < 0)
{
/* ???????? */
}
/*endif*/
fe->timed_step = T38_TIMED_STEP_HDLC_MODEM_3;
at_put_response_code(&s->at_state, AT_RESPONSE_CODE_CONNECT);
/* We should now wait enough time for everything to clear through an analogue modem at the far end. */
delay = bits_to_us(s, fe->hdlc_tx.extra_bits);
if (s->hdlc_tx.len == 0)
span_log(&s->logging, SPAN_LOG_FLOW, "No new frame or end transmission condition.\n");
/*endif*/
}
else
{ {
/* End of transmission */ /* End of transmission */
s->hdlc_tx.len = 0; s->hdlc_tx.len = 0;
s->hdlc_tx.final = FALSE; s->hdlc_tx.final = FALSE;
category = (s->t38_fe.current_tx_data_type == T38_DATA_V21) ? T38_PACKET_CATEGORY_CONTROL_DATA : T38_PACKET_CATEGORY_IMAGE_DATA; category = (fe->current_tx_data_type == T38_DATA_V21) ? T38_PACKET_CATEGORY_CONTROL_DATA : T38_PACKET_CATEGORY_IMAGE_DATA;
if (t38_core_send_data(&fe->t38, previous, T38_FIELD_HDLC_FCS_OK, NULL, 0, category) < 0) if (t38_core_send_data(&fe->t38, previous, T38_FIELD_HDLC_FCS_OK, NULL, 0, category) < 0)
{ {
/* ???????? */ /* ???????? */
} }
/*endif*/
fe->timed_step = T38_TIMED_STEP_HDLC_MODEM_5; fe->timed_step = T38_TIMED_STEP_HDLC_MODEM_5;
/* We add a bit of extra time here, as with some implementations /* We add a bit of extra time here, as with some implementations
the carrier falling too abruptly causes data loss. */ the carrier falling too abruptly causes data loss. */
delay = bits_to_us(s, fe->hdlc_tx.extra_bits); delay = bits_to_us(s, fe->hdlc_tx.extra_bits);
if (s->t38_fe.ms_per_tx_chunk) if (fe->ms_per_tx_chunk)
delay += 100000; delay += 100000;
/*endif*/
front_end_status(s, T30_FRONT_END_SEND_STEP_COMPLETE); front_end_status(s, T30_FRONT_END_SEND_STEP_COMPLETE);
break;
}
/* Finish the current frame off, and prepare for the next one. */
category = (s->t38_fe.current_tx_data_type == T38_DATA_V21) ? T38_PACKET_CATEGORY_CONTROL_DATA : T38_PACKET_CATEGORY_IMAGE_DATA;
if (t38_core_send_data(&fe->t38, previous, T38_FIELD_HDLC_FCS_OK, NULL, 0, category) < 0)
{
/* ???????? */
} }
fe->timed_step = T38_TIMED_STEP_HDLC_MODEM_3; /*endif*/
at_put_response_code(&s->at_state, AT_RESPONSE_CODE_CONNECT);
/* We should now wait enough time for everything to clear through an analogue modem at the far end. */
delay = bits_to_us(s, fe->hdlc_tx.extra_bits);
if (s->hdlc_tx.len == 0)
span_log(&s->logging, SPAN_LOG_FLOW, "No new frame or end transmission condition.\n");
break; break;
case T38_TIMED_STEP_HDLC_MODEM_5: case T38_TIMED_STEP_HDLC_MODEM_5:
/* Note that some boxes do not like us sending a T38_FIELD_HDLC_SIG_END at this point. /* Note that some boxes do not like us sending a T38_FIELD_HDLC_SIG_END at this point.
A T38_IND_NO_SIGNAL should always be OK. */ A T38_IND_NO_SIGNAL should always be OK. */
category = (s->t38_fe.current_tx_data_type == T38_DATA_V21) ? T38_PACKET_CATEGORY_CONTROL_DATA_END : T38_PACKET_CATEGORY_IMAGE_DATA_END; category = (fe->current_tx_data_type == T38_DATA_V21) ? T38_PACKET_CATEGORY_CONTROL_DATA_END : T38_PACKET_CATEGORY_IMAGE_DATA_END;
if (t38_core_send_data(&fe->t38, fe->current_tx_data_type, T38_FIELD_HDLC_SIG_END, NULL, 0, category) < 0) if (t38_core_send_data(&fe->t38, fe->current_tx_data_type, T38_FIELD_HDLC_SIG_END, NULL, 0, category) < 0)
{ {
/* ???????? */ /* ???????? */
} }
/*endif*/
if ((delay = t38_core_send_indicator(&fe->t38, T38_IND_NO_SIGNAL)) < 0) if ((delay = t38_core_send_indicator(&fe->t38, T38_IND_NO_SIGNAL)) < 0)
{ {
/* ???????? */ /* ???????? */
} }
/*endif*/
fe->timed_step = T38_TIMED_STEP_NONE; fe->timed_step = T38_TIMED_STEP_NONE;
at_put_response_code(&s->at_state, AT_RESPONSE_CODE_OK); at_put_response_code(&s->at_state, AT_RESPONSE_CODE_OK);
t31_set_at_rx_mode(s, AT_MODE_OFFHOOK_COMMAND); t31_set_at_rx_mode(s, AT_MODE_OFFHOOK_COMMAND);
return 0; return 0;
} }
/*endswitch*/
} }
/*endfor*/
return delay; return delay;
} }
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/
...@@ -1016,7 +1085,7 @@ static int stream_ced(t31_state_t *s) ...@@ -1016,7 +1085,7 @@ static int stream_ced(t31_state_t *s)
{ {
/* ???????? */ /* ???????? */
} }
delay = 200000; delay = (fe->ms_per_tx_chunk) ? 200000 : 0;
fe->next_tx_samples = fe->samples; fe->next_tx_samples = fe->samples;
break; break;
case T38_TIMED_STEP_CED_2: case T38_TIMED_STEP_CED_2:
...@@ -1059,7 +1128,7 @@ static int stream_cng(t31_state_t *s) ...@@ -1059,7 +1128,7 @@ static int stream_cng(t31_state_t *s)
{ {
/* ???????? */ /* ???????? */
} }
delay = 200000; delay = (fe->ms_per_tx_chunk) ? 200000 : 0;
fe->next_tx_samples = fe->samples; fe->next_tx_samples = fe->samples;
break; break;
case T38_TIMED_STEP_CNG_2: case T38_TIMED_STEP_CNG_2:
...@@ -1071,10 +1140,13 @@ static int stream_cng(t31_state_t *s) ...@@ -1071,10 +1140,13 @@ static int stream_cng(t31_state_t *s)
{ {
/* ???????? */ /* ???????? */
} }
/*endif*/
fe->current_tx_data_type = T38_DATA_NONE; fe->current_tx_data_type = T38_DATA_NONE;
return delay; return delay;
} }
/*endswitch*/
} }
/*endfor*/
return delay; return delay;
} }
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/
...@@ -1087,6 +1159,7 @@ SPAN_DECLARE(int) t31_t38_send_timeout(t31_state_t *s, int samples) ...@@ -1087,6 +1159,7 @@ SPAN_DECLARE(int) t31_t38_send_timeout(t31_state_t *s, int samples)
fe = &s->t38_fe; fe = &s->t38_fe;
if (fe->current_rx_type == T30_MODEM_DONE || fe->current_tx_type == T30_MODEM_DONE) if (fe->current_rx_type == T30_MODEM_DONE || fe->current_tx_type == T30_MODEM_DONE)
return TRUE; return TRUE;
/*endif*/
fe->samples += samples; fe->samples += samples;
if (fe->timeout_rx_samples && fe->samples > fe->timeout_rx_samples) if (fe->timeout_rx_samples && fe->samples > fe->timeout_rx_samples)
...@@ -1095,12 +1168,15 @@ SPAN_DECLARE(int) t31_t38_send_timeout(t31_state_t *s, int samples) ...@@ -1095,12 +1168,15 @@ SPAN_DECLARE(int) t31_t38_send_timeout(t31_state_t *s, int samples)
fe->timeout_rx_samples = 0; fe->timeout_rx_samples = 0;
front_end_status(s, T30_FRONT_END_RECEIVE_COMPLETE); front_end_status(s, T30_FRONT_END_RECEIVE_COMPLETE);
} }
/*endif*/
if (fe->timed_step == T38_TIMED_STEP_NONE) if (fe->timed_step == T38_TIMED_STEP_NONE)
return FALSE; return FALSE;
/*endif*/
/* Wait until the right time comes along, unless we are working in "no delays" mode, while talking to an /* Wait until the right time comes along, unless we are working in "no delays" mode, while talking to an
IAF terminal. */ IAF terminal. */
if (fe->ms_per_tx_chunk && fe->samples < fe->next_tx_samples) if (fe->ms_per_tx_chunk && fe->samples < fe->next_tx_samples)
return FALSE; return FALSE;
/*endif*/
/* Its time to send something */ /* Its time to send something */
delay = 0; delay = 0;
switch (fe->timed_step & 0xFFF0) switch (fe->timed_step & 0xFFF0)
...@@ -1111,9 +1187,9 @@ SPAN_DECLARE(int) t31_t38_send_timeout(t31_state_t *s, int samples) ...@@ -1111,9 +1187,9 @@ SPAN_DECLARE(int) t31_t38_send_timeout(t31_state_t *s, int samples)
case T38_TIMED_STEP_HDLC_MODEM: case T38_TIMED_STEP_HDLC_MODEM:
delay = stream_hdlc(s); delay = stream_hdlc(s);
break; break;
//case T38_TIMED_STEP_FAKE_HDLC_MODEM: case T38_TIMED_STEP_FAKE_HDLC_MODEM:
// delay = stream_fake_hdlc(s); // delay = stream_fake_hdlc(s);
// break; break;
case T38_TIMED_STEP_CED: case T38_TIMED_STEP_CED:
delay = stream_ced(s); delay = stream_ced(s);
break; break;
...@@ -1125,7 +1201,11 @@ SPAN_DECLARE(int) t31_t38_send_timeout(t31_state_t *s, int samples) ...@@ -1125,7 +1201,11 @@ SPAN_DECLARE(int) t31_t38_send_timeout(t31_state_t *s, int samples)
fe->timed_step = T38_TIMED_STEP_NONE; fe->timed_step = T38_TIMED_STEP_NONE;
front_end_status(s, T30_FRONT_END_SEND_STEP_COMPLETE); front_end_status(s, T30_FRONT_END_SEND_STEP_COMPLETE);
break; break;
case T38_TIMED_STEP_NO_SIGNAL:
// delay = stream_no_signal(s);
break;
} }
/*endswitch*/
fe->next_tx_samples += us_to_samples(delay); fe->next_tx_samples += us_to_samples(delay);
return FALSE; return FALSE;
} }
...@@ -1151,6 +1231,7 @@ static int t31_modem_control_handler(at_state_t *s, void *user_data, int op, con ...@@ -1151,6 +1231,7 @@ static int t31_modem_control_handler(at_state_t *s, void *user_data, int op, con
/* Tell the application to release further data */ /* Tell the application to release further data */
at_modem_control(&t->at_state, AT_MODEM_CONTROL_CTS, (void *) 1); at_modem_control(&t->at_state, AT_MODEM_CONTROL_CTS, (void *) 1);
} }
/*endif*/
if (t->at_state.rx_signal_present) if (t->at_state.rx_signal_present)
{ {
t->at_state.rx_data[t->at_state.rx_data_bytes++] = DLE; t->at_state.rx_data[t->at_state.rx_data_bytes++] = DLE;
...@@ -1161,6 +1242,7 @@ static int t31_modem_control_handler(at_state_t *s, void *user_data, int op, con ...@@ -1161,6 +1242,7 @@ static int t31_modem_control_handler(at_state_t *s, void *user_data, int op, con
t->at_state.rx_data_bytes); t->at_state.rx_data_bytes);
t->at_state.rx_data_bytes = 0; t->at_state.rx_data_bytes = 0;
} }
/*endif*/
restart_modem(t, FAX_MODEM_SILENCE_TX); restart_modem(t, FAX_MODEM_SILENCE_TX);
break; break;
case AT_MODEM_CONTROL_RESTART: case AT_MODEM_CONTROL_RESTART:
...@@ -1171,8 +1253,10 @@ static int t31_modem_control_handler(at_state_t *s, void *user_data, int op, con ...@@ -1171,8 +1253,10 @@ static int t31_modem_control_handler(at_state_t *s, void *user_data, int op, con
t->dte_data_timeout = t->call_samples + ms_to_samples((intptr_t) num); t->dte_data_timeout = t->call_samples + ms_to_samples((intptr_t) num);
else else
t->dte_data_timeout = 0; t->dte_data_timeout = 0;
/*endif*/
return 0; return 0;
} }
/*endswitch*/
return t->modem_control_handler(t, t->modem_control_user_data, op, num); return t->modem_control_handler(t, t->modem_control_user_data, op, num);
} }
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/
...@@ -1212,6 +1296,7 @@ static void non_ecm_rx_status(void *user_data, int status) ...@@ -1212,6 +1296,7 @@ static void non_ecm_rx_status(void *user_data, int status)
at_put_response_code(&s->at_state, AT_RESPONSE_CODE_NO_CARRIER); at_put_response_code(&s->at_state, AT_RESPONSE_CODE_NO_CARRIER);
t31_set_at_rx_mode(s, AT_MODE_OFFHOOK_COMMAND); t31_set_at_rx_mode(s, AT_MODE_OFFHOOK_COMMAND);
} }
/*endif*/
s->at_state.rx_signal_present = FALSE; s->at_state.rx_signal_present = FALSE;
s->at_state.rx_trained = FALSE; s->at_state.rx_trained = FALSE;
s->audio.modems.rx_trained = FALSE; s->audio.modems.rx_trained = FALSE;
...@@ -1219,8 +1304,10 @@ static void non_ecm_rx_status(void *user_data, int status) ...@@ -1219,8 +1304,10 @@ static void non_ecm_rx_status(void *user_data, int status)
default: default:
if (s->at_state.p.result_code_format) if (s->at_state.p.result_code_format)
span_log(&s->logging, SPAN_LOG_FLOW, "Eh!\n"); span_log(&s->logging, SPAN_LOG_FLOW, "Eh!\n");
/*endif*/
break; break;
} }
/*endswitch*/
} }
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/
...@@ -1233,12 +1320,14 @@ static void non_ecm_put_bit(void *user_data, int bit) ...@@ -1233,12 +1320,14 @@ static void non_ecm_put_bit(void *user_data, int bit)
non_ecm_rx_status(user_data, bit); non_ecm_rx_status(user_data, bit);
return; return;
} }
/*endif*/
s = (t31_state_t *) user_data; s = (t31_state_t *) user_data;
s->audio.current_byte = (s->audio.current_byte >> 1) | (bit << 7); s->audio.current_byte = (s->audio.current_byte >> 1) | (bit << 7);
if (++s->audio.bit_no >= 8) if (++s->audio.bit_no >= 8)
{ {
if (s->audio.current_byte == DLE) if (s->audio.current_byte == DLE)
s->at_state.rx_data[s->at_state.rx_data_bytes++] = DLE; s->at_state.rx_data[s->at_state.rx_data_bytes++] = DLE;
/*endif*/
s->at_state.rx_data[s->at_state.rx_data_bytes++] = (uint8_t) s->audio.current_byte; s->at_state.rx_data[s->at_state.rx_data_bytes++] = (uint8_t) s->audio.current_byte;
if (s->at_state.rx_data_bytes >= 250) if (s->at_state.rx_data_bytes >= 250)
{ {
...@@ -1248,9 +1337,11 @@ static void non_ecm_put_bit(void *user_data, int bit) ...@@ -1248,9 +1337,11 @@ static void non_ecm_put_bit(void *user_data, int bit)
s->at_state.rx_data_bytes); s->at_state.rx_data_bytes);
s->at_state.rx_data_bytes = 0; s->at_state.rx_data_bytes = 0;
} }
/*endif*/
s->audio.bit_no = 0; s->audio.bit_no = 0;
s->audio.current_byte = 0; s->audio.current_byte = 0;
} }
/*endif*/
} }
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/
...@@ -1265,6 +1356,7 @@ static void non_ecm_put(void *user_data, const uint8_t buf[], int len) ...@@ -1265,6 +1356,7 @@ static void non_ecm_put(void *user_data, const uint8_t buf[], int len)
{ {
if (buf[i] == DLE) if (buf[i] == DLE)
s->at_state.rx_data[s->at_state.rx_data_bytes++] = DLE; s->at_state.rx_data[s->at_state.rx_data_bytes++] = DLE;
/*endif*/
s->at_state.rx_data[s->at_state.rx_data_bytes++] = buf[i]; s->at_state.rx_data[s->at_state.rx_data_bytes++] = buf[i];
if (s->at_state.rx_data_bytes >= 250) if (s->at_state.rx_data_bytes >= 250)
{ {
...@@ -1274,7 +1366,9 @@ static void non_ecm_put(void *user_data, const uint8_t buf[], int len) ...@@ -1274,7 +1366,9 @@ static void non_ecm_put(void *user_data, const uint8_t buf[], int len)
s->at_state.rx_data_bytes); s->at_state.rx_data_bytes);
s->at_state.rx_data_bytes = 0; s->at_state.rx_data_bytes = 0;
} }
/*endif*/
} }
/*endfor*/
s->audio.bit_no = 0; s->audio.bit_no = 0;
s->audio.current_byte = 0; s->audio.current_byte = 0;
} }
...@@ -1297,6 +1391,7 @@ static int non_ecm_get_bit(void *user_data) ...@@ -1297,6 +1391,7 @@ static int non_ecm_get_bit(void *user_data)
s->tx.out_bytes = T31_TX_BUF_LEN - 1; s->tx.out_bytes = T31_TX_BUF_LEN - 1;
span_log(&s->logging, SPAN_LOG_FLOW, "End of transmit buffer reached!\n"); span_log(&s->logging, SPAN_LOG_FLOW, "End of transmit buffer reached!\n");
} }
/*endif*/
if (s->tx.holding) if (s->tx.holding)
{ {
/* See if the buffer is approaching empty. It might be time to /* See if the buffer is approaching empty. It might be time to
...@@ -1307,7 +1402,9 @@ static int non_ecm_get_bit(void *user_data) ...@@ -1307,7 +1402,9 @@ static int non_ecm_get_bit(void *user_data)
/* Tell the application to release further data */ /* Tell the application to release further data */
at_modem_control(&s->at_state, AT_MODEM_CONTROL_CTS, (void *) 1); at_modem_control(&s->at_state, AT_MODEM_CONTROL_CTS, (void *) 1);
} }
/*endif*/
} }
/*endif*/
s->tx.data_started = TRUE; s->tx.data_started = TRUE;
} }
else else
...@@ -1319,12 +1416,15 @@ static int non_ecm_get_bit(void *user_data) ...@@ -1319,12 +1416,15 @@ static int non_ecm_get_bit(void *user_data)
it has finally shut down, an OK response will be sent. */ it has finally shut down, an OK response will be sent. */
return SIG_STATUS_END_OF_DATA; return SIG_STATUS_END_OF_DATA;
} }
/*endif*/
/* Fill with 0xFF bytes at the start of transmission, or 0x00 if we are in /* Fill with 0xFF bytes at the start of transmission, or 0x00 if we are in
the middle of transmission. This follows T.31 and T.30 practice. */ the middle of transmission. This follows T.31 and T.30 practice. */
s->audio.current_byte = (s->tx.data_started) ? 0x00 : 0xFF; s->audio.current_byte = (s->tx.data_started) ? 0x00 : 0xFF;
} }
/*endif*/
s->audio.bit_no = 8; s->audio.bit_no = 8;
} }
/*endif*/
s->audio.bit_no--; s->audio.bit_no--;
bit = s->audio.current_byte & 1; bit = s->audio.current_byte & 1;
s->audio.current_byte >>= 1; s->audio.current_byte >>= 1;
...@@ -1349,6 +1449,7 @@ static int non_ecm_get(void *user_data, uint8_t buf[], int len) ...@@ -1349,6 +1449,7 @@ static int non_ecm_get(void *user_data, uint8_t buf[], int len)
s->tx.out_bytes = T31_TX_BUF_LEN - 1; s->tx.out_bytes = T31_TX_BUF_LEN - 1;
span_log(&s->logging, SPAN_LOG_FLOW, "End of transmit buffer reached!\n"); span_log(&s->logging, SPAN_LOG_FLOW, "End of transmit buffer reached!\n");
} }
/*endif*/
if (s->tx.holding) if (s->tx.holding)
{ {
/* See if the buffer is approaching empty. It might be time to release flow control. */ /* See if the buffer is approaching empty. It might be time to release flow control. */
...@@ -1358,7 +1459,9 @@ static int non_ecm_get(void *user_data, uint8_t buf[], int len) ...@@ -1358,7 +1459,9 @@ static int non_ecm_get(void *user_data, uint8_t buf[], int len)
/* Tell the application to release further data */ /* Tell the application to release further data */
at_modem_control(&s->at_state, AT_MODEM_CONTROL_CTS, (void *) 1); at_modem_control(&s->at_state, AT_MODEM_CONTROL_CTS, (void *) 1);
} }
/*endif*/
} }
/*endif*/
s->tx.data_started = TRUE; s->tx.data_started = TRUE;
} }
else else
...@@ -1371,11 +1474,14 @@ static int non_ecm_get(void *user_data, uint8_t buf[], int len) ...@@ -1371,11 +1474,14 @@ static int non_ecm_get(void *user_data, uint8_t buf[], int len)
//return SIG_STATUS_END_OF_DATA; //return SIG_STATUS_END_OF_DATA;
return i; return i;
} }
/*endif*/
/* Fill with 0xFF bytes at the start of transmission, or 0x00 if we are in /* Fill with 0xFF bytes at the start of transmission, or 0x00 if we are in
the middle of transmission. This follows T.31 and T.30 practice. */ the middle of transmission. This follows T.31 and T.30 practice. */
buf[i] = (s->tx.data_started) ? 0x00 : 0xFF; buf[i] = (s->tx.data_started) ? 0x00 : 0xFF;
} }
/*endif*/
} }
/*endfor*/
s->audio.bit_no = 0; s->audio.bit_no = 0;
s->audio.current_byte = 0; s->audio.current_byte = 0;
return len; return len;
...@@ -1415,6 +1521,7 @@ static void hdlc_tx_underflow(void *user_data) ...@@ -1415,6 +1521,7 @@ static void hdlc_tx_underflow(void *user_data)
{ {
at_put_response_code(&s->at_state, AT_RESPONSE_CODE_CONNECT); at_put_response_code(&s->at_state, AT_RESPONSE_CODE_CONNECT);
} }
/*endif*/
} }
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/
...@@ -1445,6 +1552,7 @@ static void hdlc_rx_status(void *user_data, int status) ...@@ -1445,6 +1552,7 @@ static void hdlc_rx_status(void *user_data, int status)
s->rx_frame_received = FALSE; s->rx_frame_received = FALSE;
s->audio.modems.rx_frame_received = FALSE; s->audio.modems.rx_frame_received = FALSE;
} }
/*endif*/
break; break;
case SIG_STATUS_CARRIER_DOWN: case SIG_STATUS_CARRIER_DOWN:
if (s->rx_frame_received) if (s->rx_frame_received)
...@@ -1460,6 +1568,7 @@ static void hdlc_rx_status(void *user_data, int status) ...@@ -1460,6 +1568,7 @@ static void hdlc_rx_status(void *user_data, int status)
{ {
at_put_response_code(&s->at_state, AT_RESPONSE_CODE_NO_CARRIER); at_put_response_code(&s->at_state, AT_RESPONSE_CODE_NO_CARRIER);
} }
/*endif*/
s->at_state.dte_is_waiting = FALSE; s->at_state.dte_is_waiting = FALSE;
t31_set_at_rx_mode(s, AT_MODE_OFFHOOK_COMMAND); t31_set_at_rx_mode(s, AT_MODE_OFFHOOK_COMMAND);
} }
...@@ -1468,7 +1577,9 @@ static void hdlc_rx_status(void *user_data, int status) ...@@ -1468,7 +1577,9 @@ static void hdlc_rx_status(void *user_data, int status)
buf[0] = AT_RESPONSE_CODE_NO_CARRIER; buf[0] = AT_RESPONSE_CODE_NO_CARRIER;
queue_write_msg(s->rx_queue, buf, 1); queue_write_msg(s->rx_queue, buf, 1);
} }
/*endif*/
} }
/*endif*/
s->at_state.rx_signal_present = FALSE; s->at_state.rx_signal_present = FALSE;
s->at_state.rx_trained = FALSE; s->at_state.rx_trained = FALSE;
s->audio.modems.rx_trained = FALSE; s->audio.modems.rx_trained = FALSE;
...@@ -1481,6 +1592,7 @@ static void hdlc_rx_status(void *user_data, int status) ...@@ -1481,6 +1592,7 @@ static void hdlc_rx_status(void *user_data, int status)
s->modem = FAX_MODEM_V21_RX; s->modem = FAX_MODEM_V21_RX;
s->at_state.transmit = FALSE; s->at_state.transmit = FALSE;
} }
/*endif*/
if (s->modem == FAX_MODEM_V17_RX || s->modem == FAX_MODEM_V27TER_RX || s->modem == FAX_MODEM_V29_RX) if (s->modem == FAX_MODEM_V17_RX || s->modem == FAX_MODEM_V27TER_RX || s->modem == FAX_MODEM_V29_RX)
{ {
/* V.21 has been detected while expecting a different carrier. /* V.21 has been detected while expecting a different carrier.
...@@ -1506,6 +1618,7 @@ static void hdlc_rx_status(void *user_data, int status) ...@@ -1506,6 +1618,7 @@ static void hdlc_rx_status(void *user_data, int status)
s->audio.modems.rx_frame_received = FALSE; s->audio.modems.rx_frame_received = FALSE;
at_put_response_code(&s->at_state, AT_RESPONSE_CODE_FCERROR); at_put_response_code(&s->at_state, AT_RESPONSE_CODE_FCERROR);
} }
/*endif*/
} }
else else
{ {
...@@ -1523,8 +1636,11 @@ static void hdlc_rx_status(void *user_data, int status) ...@@ -1523,8 +1636,11 @@ static void hdlc_rx_status(void *user_data, int status)
buf[0] = AT_RESPONSE_CODE_CONNECT; buf[0] = AT_RESPONSE_CODE_CONNECT;
queue_write_msg(s->rx_queue, buf, 1); queue_write_msg(s->rx_queue, buf, 1);
} }
/*endif*/
} }
/*endif*/
} }
/*endif*/
break; break;
case SIG_STATUS_ABORT: case SIG_STATUS_ABORT:
/* Just ignore these */ /* Just ignore these */
...@@ -1533,6 +1649,7 @@ static void hdlc_rx_status(void *user_data, int status) ...@@ -1533,6 +1649,7 @@ static void hdlc_rx_status(void *user_data, int status)
span_log(&s->logging, SPAN_LOG_WARNING, "Unexpected HDLC rx status - %d!\n", status); span_log(&s->logging, SPAN_LOG_WARNING, "Unexpected HDLC rx status - %d!\n", status);
break; break;
} }
/*endswitch*/
} }
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/
...@@ -1547,6 +1664,7 @@ static void hdlc_accept_frame(void *user_data, const uint8_t *msg, int len, int ...@@ -1547,6 +1664,7 @@ static void hdlc_accept_frame(void *user_data, const uint8_t *msg, int len, int
hdlc_rx_status(user_data, len); hdlc_rx_status(user_data, len);
return; return;
} }
/*endif*/
s = (t31_state_t *) user_data; s = (t31_state_t *) user_data;
if (!s->rx_frame_received) if (!s->rx_frame_received)
{ {
...@@ -1562,7 +1680,9 @@ static void hdlc_accept_frame(void *user_data, const uint8_t *msg, int len, int ...@@ -1562,7 +1680,9 @@ static void hdlc_accept_frame(void *user_data, const uint8_t *msg, int len, int
buf[0] = AT_RESPONSE_CODE_CONNECT; buf[0] = AT_RESPONSE_CODE_CONNECT;
queue_write_msg(s->rx_queue, buf, 1); queue_write_msg(s->rx_queue, buf, 1);
} }
/*endif*/
} }
/*endif*/
/* If OK is pending then we just ignore whatever comes in */ /* If OK is pending then we just ignore whatever comes in */
if (!s->at_state.ok_is_pending) if (!s->at_state.ok_is_pending)
{ {
...@@ -1575,8 +1695,10 @@ static void hdlc_accept_frame(void *user_data, const uint8_t *msg, int len, int ...@@ -1575,8 +1695,10 @@ static void hdlc_accept_frame(void *user_data, const uint8_t *msg, int len, int
{ {
if (msg[i] == DLE) if (msg[i] == DLE)
s->at_state.rx_data[s->at_state.rx_data_bytes++] = DLE; s->at_state.rx_data[s->at_state.rx_data_bytes++] = DLE;
/*endif*/
s->at_state.rx_data[s->at_state.rx_data_bytes++] = msg[i]; s->at_state.rx_data[s->at_state.rx_data_bytes++] = msg[i];
} }
/*endfor*/
s->at_state.rx_data[s->at_state.rx_data_bytes++] = DLE; s->at_state.rx_data[s->at_state.rx_data_bytes++] = DLE;
s->at_state.rx_data[s->at_state.rx_data_bytes++] = ETX; s->at_state.rx_data[s->at_state.rx_data_bytes++] = ETX;
s->at_state.at_tx_handler(&s->at_state, s->at_state.at_tx_user_data, s->at_state.rx_data, s->at_state.rx_data_bytes); s->at_state.at_tx_handler(&s->at_state, s->at_state.at_tx_user_data, s->at_state.rx_data, s->at_state.rx_data_bytes);
...@@ -1594,6 +1716,7 @@ static void hdlc_accept_frame(void *user_data, const uint8_t *msg, int len, int ...@@ -1594,6 +1716,7 @@ static void hdlc_accept_frame(void *user_data, const uint8_t *msg, int len, int
s->rx_frame_received = FALSE; s->rx_frame_received = FALSE;
s->audio.modems.rx_frame_received = FALSE; s->audio.modems.rx_frame_received = FALSE;
} }
/*endif*/
} }
else else
{ {
...@@ -1604,7 +1727,9 @@ static void hdlc_accept_frame(void *user_data, const uint8_t *msg, int len, int ...@@ -1604,7 +1727,9 @@ static void hdlc_accept_frame(void *user_data, const uint8_t *msg, int len, int
memcpy(buf + 1, msg, len + 2); memcpy(buf + 1, msg, len + 2);
queue_write_msg(s->rx_queue, buf, len + 3); queue_write_msg(s->rx_queue, buf, len + 3);
} }
/*endif*/
} }
/*endif*/
t31_set_at_rx_mode(s, AT_MODE_OFFHOOK_COMMAND); t31_set_at_rx_mode(s, AT_MODE_OFFHOOK_COMMAND);
} }
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/
...@@ -1612,8 +1737,8 @@ static void hdlc_accept_frame(void *user_data, const uint8_t *msg, int len, int ...@@ -1612,8 +1737,8 @@ static void hdlc_accept_frame(void *user_data, const uint8_t *msg, int len, int
static void t31_v21_rx(t31_state_t *s) static void t31_v21_rx(t31_state_t *s)
{ {
s->at_state.ok_is_pending = FALSE; s->at_state.ok_is_pending = FALSE;
s->hdlc_tx.final = FALSE;
s->hdlc_tx.len = 0; s->hdlc_tx.len = 0;
s->hdlc_tx.final = FALSE;
s->dled = FALSE; s->dled = FALSE;
hdlc_rx_init(&s->audio.modems.hdlc_rx, FALSE, TRUE, HDLC_FRAMING_OK_THRESHOLD, hdlc_accept_frame, s); hdlc_rx_init(&s->audio.modems.hdlc_rx, FALSE, TRUE, HDLC_FRAMING_OK_THRESHOLD, hdlc_accept_frame, s);
fax_modems_start_slow_modem(&s->audio.modems, FAX_MODEM_V21_RX); fax_modems_start_slow_modem(&s->audio.modems, FAX_MODEM_V21_RX);
...@@ -1630,6 +1755,7 @@ static int restart_modem(t31_state_t *s, int new_modem) ...@@ -1630,6 +1755,7 @@ static int restart_modem(t31_state_t *s, int new_modem)
span_log(&s->logging, SPAN_LOG_FLOW, "Restart modem %d\n", new_modem); span_log(&s->logging, SPAN_LOG_FLOW, "Restart modem %d\n", new_modem);
if (s->modem == new_modem) if (s->modem == new_modem)
return 0; return 0;
/*endif*/
queue_flush(s->rx_queue); queue_flush(s->rx_queue);
s->modem = new_modem; s->modem = new_modem;
s->tx.final = FALSE; s->tx.final = FALSE;
...@@ -1662,6 +1788,7 @@ static int restart_modem(t31_state_t *s, int new_modem) ...@@ -1662,6 +1788,7 @@ static int restart_modem(t31_state_t *s, int new_modem)
fax_modems_set_tx_handler(t, (span_tx_handler_t) &modem_connect_tones_tx, &t->connect_tx); fax_modems_set_tx_handler(t, (span_tx_handler_t) &modem_connect_tones_tx, &t->connect_tx);
fax_modems_set_next_tx_handler(t, (span_tx_handler_t) NULL, NULL); fax_modems_set_next_tx_handler(t, (span_tx_handler_t) NULL, NULL);
} }
/*endif*/
s->at_state.transmit = TRUE; s->at_state.transmit = TRUE;
break; break;
case FAX_MODEM_NOCNG_TONE: case FAX_MODEM_NOCNG_TONE:
...@@ -1675,6 +1802,7 @@ static int restart_modem(t31_state_t *s, int new_modem) ...@@ -1675,6 +1802,7 @@ static int restart_modem(t31_state_t *s, int new_modem)
silence_gen_set(&t->silence_gen, 0); silence_gen_set(&t->silence_gen, 0);
fax_modems_set_tx_handler(t, (span_tx_handler_t) &silence_gen, &t->silence_gen); fax_modems_set_tx_handler(t, (span_tx_handler_t) &silence_gen, &t->silence_gen);
} }
/*endif*/
s->at_state.transmit = FALSE; s->at_state.transmit = FALSE;
break; break;
case FAX_MODEM_CED_TONE: case FAX_MODEM_CED_TONE:
...@@ -1690,6 +1818,7 @@ static int restart_modem(t31_state_t *s, int new_modem) ...@@ -1690,6 +1818,7 @@ static int restart_modem(t31_state_t *s, int new_modem)
fax_modems_set_tx_handler(t, (span_tx_handler_t) &modem_connect_tones_tx, &t->connect_tx); fax_modems_set_tx_handler(t, (span_tx_handler_t) &modem_connect_tones_tx, &t->connect_tx);
fax_modems_set_next_tx_handler(t, (span_tx_handler_t) NULL, NULL); fax_modems_set_next_tx_handler(t, (span_tx_handler_t) NULL, NULL);
} }
/*endif*/
s->at_state.transmit = TRUE; s->at_state.transmit = TRUE;
break; break;
case FAX_MODEM_V21_RX: case FAX_MODEM_V21_RX:
...@@ -1701,6 +1830,7 @@ static int restart_modem(t31_state_t *s, int new_modem) ...@@ -1701,6 +1830,7 @@ static int restart_modem(t31_state_t *s, int new_modem)
t31_v21_rx(s); t31_v21_rx(s);
fax_modems_set_rx_handler(t, (span_rx_handler_t) &fsk_rx, &t->v21_rx, (span_rx_fillin_handler_t) &fsk_rx_fillin, &t->v21_rx); fax_modems_set_rx_handler(t, (span_rx_handler_t) &fsk_rx, &t->v21_rx, (span_rx_fillin_handler_t) &fsk_rx_fillin, &t->v21_rx);
} }
/*endif*/
break; break;
case FAX_MODEM_V21_TX: case FAX_MODEM_V21_TX:
if (s->t38_mode) if (s->t38_mode)
...@@ -1720,8 +1850,9 @@ static int restart_modem(t31_state_t *s, int new_modem) ...@@ -1720,8 +1850,9 @@ static int restart_modem(t31_state_t *s, int new_modem)
fax_modems_set_tx_handler(t, (span_tx_handler_t) &fsk_tx, &t->v21_tx); fax_modems_set_tx_handler(t, (span_tx_handler_t) &fsk_tx, &t->v21_tx);
fax_modems_set_next_tx_handler(t, (span_tx_handler_t) NULL, NULL); fax_modems_set_next_tx_handler(t, (span_tx_handler_t) NULL, NULL);
} }
s->hdlc_tx.final = FALSE; /*endif*/
s->hdlc_tx.len = 0; s->hdlc_tx.len = 0;
s->hdlc_tx.final = FALSE;
s->dled = FALSE; s->dled = FALSE;
s->at_state.transmit = TRUE; s->at_state.transmit = TRUE;
break; break;
...@@ -1734,6 +1865,7 @@ static int restart_modem(t31_state_t *s, int new_modem) ...@@ -1734,6 +1865,7 @@ static int restart_modem(t31_state_t *s, int new_modem)
/* Allow for +FCERROR/+FRH:3 */ /* Allow for +FCERROR/+FRH:3 */
t31_v21_rx(s); t31_v21_rx(s);
} }
/*endif*/
s->at_state.transmit = FALSE; s->at_state.transmit = FALSE;
break; break;
case FAX_MODEM_V17_TX: case FAX_MODEM_V17_TX:
...@@ -1758,6 +1890,7 @@ static int restart_modem(t31_state_t *s, int new_modem) ...@@ -1758,6 +1890,7 @@ static int restart_modem(t31_state_t *s, int new_modem)
s->t38_fe.current_tx_data_type = T38_DATA_V17_14400; s->t38_fe.current_tx_data_type = T38_DATA_V17_14400;
break; break;
} }
/*endswitch*/
set_octets_per_data_packet(s, s->bit_rate); set_octets_per_data_packet(s, s->bit_rate);
s->t38_fe.timed_step = (use_hdlc) ? T38_TIMED_STEP_HDLC_MODEM : T38_TIMED_STEP_NON_ECM_MODEM; s->t38_fe.timed_step = (use_hdlc) ? T38_TIMED_STEP_HDLC_MODEM : T38_TIMED_STEP_NON_ECM_MODEM;
} }
...@@ -1765,6 +1898,7 @@ static int restart_modem(t31_state_t *s, int new_modem) ...@@ -1765,6 +1898,7 @@ static int restart_modem(t31_state_t *s, int new_modem)
{ {
fax_modems_start_fast_modem(t, s->modem, s->bit_rate, s->short_train, use_hdlc); fax_modems_start_fast_modem(t, s->modem, s->bit_rate, s->short_train, use_hdlc);
} }
/*endif*/
s->tx.out_bytes = 0; s->tx.out_bytes = 0;
s->tx.data_started = FALSE; s->tx.data_started = FALSE;
s->at_state.transmit = TRUE; s->at_state.transmit = TRUE;
...@@ -1783,6 +1917,7 @@ static int restart_modem(t31_state_t *s, int new_modem) ...@@ -1783,6 +1917,7 @@ static int restart_modem(t31_state_t *s, int new_modem)
s->t38_fe.current_tx_data_type = T38_DATA_V27TER_4800; s->t38_fe.current_tx_data_type = T38_DATA_V27TER_4800;
break; break;
} }
/*endswitch*/
set_octets_per_data_packet(s, s->bit_rate); set_octets_per_data_packet(s, s->bit_rate);
s->t38_fe.timed_step = (use_hdlc) ? T38_TIMED_STEP_HDLC_MODEM : T38_TIMED_STEP_NON_ECM_MODEM; s->t38_fe.timed_step = (use_hdlc) ? T38_TIMED_STEP_HDLC_MODEM : T38_TIMED_STEP_NON_ECM_MODEM;
} }
...@@ -1790,6 +1925,7 @@ static int restart_modem(t31_state_t *s, int new_modem) ...@@ -1790,6 +1925,7 @@ static int restart_modem(t31_state_t *s, int new_modem)
{ {
fax_modems_start_fast_modem(t, s->modem, s->bit_rate, s->short_train, use_hdlc); fax_modems_start_fast_modem(t, s->modem, s->bit_rate, s->short_train, use_hdlc);
} }
/*endif*/
s->tx.out_bytes = 0; s->tx.out_bytes = 0;
s->tx.data_started = FALSE; s->tx.data_started = FALSE;
s->at_state.transmit = TRUE; s->at_state.transmit = TRUE;
...@@ -1808,6 +1944,7 @@ static int restart_modem(t31_state_t *s, int new_modem) ...@@ -1808,6 +1944,7 @@ static int restart_modem(t31_state_t *s, int new_modem)
s->t38_fe.current_tx_data_type = T38_DATA_V29_9600; s->t38_fe.current_tx_data_type = T38_DATA_V29_9600;
break; break;
} }
/*endswitch*/
set_octets_per_data_packet(s, s->bit_rate); set_octets_per_data_packet(s, s->bit_rate);
s->t38_fe.timed_step = (use_hdlc) ? T38_TIMED_STEP_HDLC_MODEM : T38_TIMED_STEP_NON_ECM_MODEM; s->t38_fe.timed_step = (use_hdlc) ? T38_TIMED_STEP_HDLC_MODEM : T38_TIMED_STEP_NON_ECM_MODEM;
} }
...@@ -1815,6 +1952,7 @@ static int restart_modem(t31_state_t *s, int new_modem) ...@@ -1815,6 +1952,7 @@ static int restart_modem(t31_state_t *s, int new_modem)
{ {
fax_modems_start_fast_modem(t, s->modem, s->bit_rate, s->short_train, use_hdlc); fax_modems_start_fast_modem(t, s->modem, s->bit_rate, s->short_train, use_hdlc);
} }
/*endif*/
s->tx.out_bytes = 0; s->tx.out_bytes = 0;
s->tx.data_started = FALSE; s->tx.data_started = FALSE;
s->at_state.transmit = TRUE; s->at_state.transmit = TRUE;
...@@ -1826,6 +1964,7 @@ static int restart_modem(t31_state_t *s, int new_modem) ...@@ -1826,6 +1964,7 @@ static int restart_modem(t31_state_t *s, int new_modem)
{ {
/* ???????? */ /* ???????? */
} }
/*endif*/
s->t38_fe.next_tx_samples = s->t38_fe.samples + ms_to_samples(700); s->t38_fe.next_tx_samples = s->t38_fe.samples + ms_to_samples(700);
s->t38_fe.timed_step = T38_TIMED_STEP_PAUSE; s->t38_fe.timed_step = T38_TIMED_STEP_PAUSE;
s->t38_fe.current_tx_data_type = T38_DATA_NONE; s->t38_fe.current_tx_data_type = T38_DATA_NONE;
...@@ -1836,6 +1975,7 @@ static int restart_modem(t31_state_t *s, int new_modem) ...@@ -1836,6 +1975,7 @@ static int restart_modem(t31_state_t *s, int new_modem)
fax_modems_set_tx_handler(t, (span_tx_handler_t) &silence_gen, &t->silence_gen); fax_modems_set_tx_handler(t, (span_tx_handler_t) &silence_gen, &t->silence_gen);
fax_modems_set_next_tx_handler(t, (span_tx_handler_t) NULL, NULL); fax_modems_set_next_tx_handler(t, (span_tx_handler_t) NULL, NULL);
} }
/*endif*/
s->at_state.transmit = FALSE; s->at_state.transmit = FALSE;
break; break;
case FAX_MODEM_SILENCE_RX: case FAX_MODEM_SILENCE_RX:
...@@ -1846,6 +1986,7 @@ static int restart_modem(t31_state_t *s, int new_modem) ...@@ -1846,6 +1986,7 @@ static int restart_modem(t31_state_t *s, int new_modem)
fax_modems_set_tx_handler(t, (span_tx_handler_t) &silence_gen, &t->silence_gen); fax_modems_set_tx_handler(t, (span_tx_handler_t) &silence_gen, &t->silence_gen);
fax_modems_set_next_tx_handler(t, (span_tx_handler_t) NULL, NULL); fax_modems_set_next_tx_handler(t, (span_tx_handler_t) NULL, NULL);
} }
/*endif*/
s->at_state.transmit = FALSE; s->at_state.transmit = FALSE;
break; break;
case FAX_MODEM_FLUSH: case FAX_MODEM_FLUSH:
...@@ -1856,6 +1997,7 @@ static int restart_modem(t31_state_t *s, int new_modem) ...@@ -1856,6 +1997,7 @@ static int restart_modem(t31_state_t *s, int new_modem)
{ {
/* ???????? */ /* ???????? */
} }
/*endif*/
} }
else else
{ {
...@@ -1865,8 +2007,10 @@ static int restart_modem(t31_state_t *s, int new_modem) ...@@ -1865,8 +2007,10 @@ static int restart_modem(t31_state_t *s, int new_modem)
fax_modems_set_next_tx_handler(t, (span_tx_handler_t) NULL, NULL); fax_modems_set_next_tx_handler(t, (span_tx_handler_t) NULL, NULL);
s->at_state.transmit = TRUE; s->at_state.transmit = TRUE;
} }
/*endif*/
break; break;
} }
/*endswitch*/
s->audio.bit_no = 0; s->audio.bit_no = 0;
s->audio.current_byte = 0xFF; s->audio.current_byte = 0xFF;
s->tx.in_bytes = 0; s->tx.in_bytes = 0;
...@@ -1896,6 +2040,7 @@ static __inline__ void dle_unstuff_hdlc(t31_state_t *s, const char *stuffed, int ...@@ -1896,6 +2040,7 @@ static __inline__ void dle_unstuff_hdlc(t31_state_t *s, const char *stuffed, int
hdlc_tx_frame(&s->audio.modems.hdlc_tx, s->hdlc_tx.buf, s->hdlc_tx.len); hdlc_tx_frame(&s->audio.modems.hdlc_tx, s->hdlc_tx.buf, s->hdlc_tx.len);
s->hdlc_tx.len = 0; s->hdlc_tx.len = 0;
} }
/*endif*/
} }
else if (stuffed[i] == SUB) else if (stuffed[i] == SUB)
{ {
...@@ -1906,6 +2051,7 @@ static __inline__ void dle_unstuff_hdlc(t31_state_t *s, const char *stuffed, int ...@@ -1906,6 +2051,7 @@ static __inline__ void dle_unstuff_hdlc(t31_state_t *s, const char *stuffed, int
{ {
s->hdlc_tx.buf[s->hdlc_tx.len++] = stuffed[i]; s->hdlc_tx.buf[s->hdlc_tx.len++] = stuffed[i];
} }
/*endif*/
} }
else else
{ {
...@@ -1913,8 +2059,11 @@ static __inline__ void dle_unstuff_hdlc(t31_state_t *s, const char *stuffed, int ...@@ -1913,8 +2059,11 @@ static __inline__ void dle_unstuff_hdlc(t31_state_t *s, const char *stuffed, int
s->dled = TRUE; s->dled = TRUE;
else else
s->hdlc_tx.buf[s->hdlc_tx.len++] = stuffed[i]; s->hdlc_tx.buf[s->hdlc_tx.len++] = stuffed[i];
/*endif*/
} }
/*endif*/
} }
/*endfor*/
} }
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/
...@@ -1933,12 +2082,14 @@ static __inline__ void dle_unstuff(t31_state_t *s, const char *stuffed, int len) ...@@ -1933,12 +2082,14 @@ static __inline__ void dle_unstuff(t31_state_t *s, const char *stuffed, int len)
t31_set_at_rx_mode(s, AT_MODE_OFFHOOK_COMMAND); t31_set_at_rx_mode(s, AT_MODE_OFFHOOK_COMMAND);
return; return;
} }
/*endif*/
} }
else if (stuffed[i] == DLE) else if (stuffed[i] == DLE)
{ {
s->dled = TRUE; s->dled = TRUE;
continue; continue;
} }
/*endif*/
s->tx.data[s->tx.in_bytes++] = stuffed[i]; s->tx.data[s->tx.in_bytes++] = stuffed[i];
if (s->tx.in_bytes > T31_TX_BUF_LEN - 1) if (s->tx.in_bytes > T31_TX_BUF_LEN - 1)
{ {
...@@ -1946,7 +2097,9 @@ static __inline__ void dle_unstuff(t31_state_t *s, const char *stuffed, int len) ...@@ -1946,7 +2097,9 @@ static __inline__ void dle_unstuff(t31_state_t *s, const char *stuffed, int len)
span_log(&s->logging, SPAN_LOG_FLOW, "No room in buffer for new data!\n"); span_log(&s->logging, SPAN_LOG_FLOW, "No room in buffer for new data!\n");
return; return;
} }
/*endif*/
} }
/*endfor*/
if (!s->tx.holding) if (!s->tx.holding)
{ {
/* See if the buffer is approaching full. We might need to apply flow control. */ /* See if the buffer is approaching full. We might need to apply flow control. */
...@@ -1956,7 +2109,9 @@ static __inline__ void dle_unstuff(t31_state_t *s, const char *stuffed, int len) ...@@ -1956,7 +2109,9 @@ static __inline__ void dle_unstuff(t31_state_t *s, const char *stuffed, int len)
/* Tell the application to hold further data */ /* Tell the application to hold further data */
at_modem_control(&s->at_state, AT_MODEM_CONTROL_CTS, (void *) 0); at_modem_control(&s->at_state, AT_MODEM_CONTROL_CTS, (void *) 0);
} }
/*endif*/
} }
/*endif*/
} }
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/
...@@ -1985,6 +2140,7 @@ static int process_class1_cmd(at_state_t *t, void *user_data, int direction, int ...@@ -1985,6 +2140,7 @@ static int process_class1_cmd(at_state_t *t, void *user_data, int direction, int
s->t38_fe.next_tx_samples = s->t38_fe.samples + ms_to_samples(val*10); s->t38_fe.next_tx_samples = s->t38_fe.samples + ms_to_samples(val*10);
else else
silence_gen_alter(&s->audio.modems.silence_gen, ms_to_samples(val*10)); silence_gen_alter(&s->audio.modems.silence_gen, ms_to_samples(val*10));
/*endif*/
s->at_state.transmit = TRUE; s->at_state.transmit = TRUE;
} }
else else
...@@ -2002,7 +2158,9 @@ static int process_class1_cmd(at_state_t *t, void *user_data, int direction, int ...@@ -2002,7 +2158,9 @@ static int process_class1_cmd(at_state_t *t, void *user_data, int direction, int
{ {
restart_modem(s, FAX_MODEM_SILENCE_RX); restart_modem(s, FAX_MODEM_SILENCE_RX);
} }
/*endif*/
} }
/*endif*/
immediate_response = FALSE; immediate_response = FALSE;
span_log(&s->logging, SPAN_LOG_FLOW, "Silence %dms\n", val*10); span_log(&s->logging, SPAN_LOG_FLOW, "Silence %dms\n", val*10);
break; break;
...@@ -2017,18 +2175,21 @@ static int process_class1_cmd(at_state_t *t, void *user_data, int direction, int ...@@ -2017,18 +2175,21 @@ static int process_class1_cmd(at_state_t *t, void *user_data, int direction, int
default: default:
return -1; return -1;
} }
/*endswitch*/
span_log(&s->logging, SPAN_LOG_FLOW, "HDLC\n"); span_log(&s->logging, SPAN_LOG_FLOW, "HDLC\n");
if (new_modem != s->modem) if (new_modem != s->modem)
{ {
restart_modem(s, new_modem); restart_modem(s, new_modem);
immediate_response = FALSE; immediate_response = FALSE;
} }
/*endif*/
s->at_state.transmit = new_transmit; s->at_state.transmit = new_transmit;
if (new_transmit) if (new_transmit)
{ {
t31_set_at_rx_mode(s, AT_MODE_HDLC); t31_set_at_rx_mode(s, AT_MODE_HDLC);
if (!s->t38_mode) if (!s->t38_mode)
at_put_response_code(&s->at_state, AT_RESPONSE_CODE_CONNECT); at_put_response_code(&s->at_state, AT_RESPONSE_CODE_CONNECT);
/*endif*/
} }
else else
{ {
...@@ -2045,17 +2206,21 @@ static int process_class1_cmd(at_state_t *t, void *user_data, int direction, int ...@@ -2045,17 +2206,21 @@ static int process_class1_cmd(at_state_t *t, void *user_data, int direction, int
{ {
if (msg[0] == AT_RESPONSE_CODE_OK) if (msg[0] == AT_RESPONSE_CODE_OK)
at_put_response_code(&s->at_state, AT_RESPONSE_CODE_CONNECT); at_put_response_code(&s->at_state, AT_RESPONSE_CODE_CONNECT);
/*endif*/
for (i = 1; i < len; i++) for (i = 1; i < len; i++)
{ {
if (msg[i] == DLE) if (msg[i] == DLE)
s->at_state.rx_data[s->at_state.rx_data_bytes++] = DLE; s->at_state.rx_data[s->at_state.rx_data_bytes++] = DLE;
/*endif*/
s->at_state.rx_data[s->at_state.rx_data_bytes++] = msg[i]; s->at_state.rx_data[s->at_state.rx_data_bytes++] = msg[i];
} }
/*endfor*/
s->at_state.rx_data[s->at_state.rx_data_bytes++] = DLE; s->at_state.rx_data[s->at_state.rx_data_bytes++] = DLE;
s->at_state.rx_data[s->at_state.rx_data_bytes++] = ETX; s->at_state.rx_data[s->at_state.rx_data_bytes++] = ETX;
s->at_state.at_tx_handler(&s->at_state, s->at_state.at_tx_user_data, s->at_state.rx_data, s->at_state.rx_data_bytes); s->at_state.at_tx_handler(&s->at_state, s->at_state.at_tx_user_data, s->at_state.rx_data, s->at_state.rx_data_bytes);
s->at_state.rx_data_bytes = 0; s->at_state.rx_data_bytes = 0;
} }
/*endif*/
at_put_response_code(&s->at_state, msg[0]); at_put_response_code(&s->at_state, msg[0]);
} }
else else
...@@ -2063,9 +2228,11 @@ static int process_class1_cmd(at_state_t *t, void *user_data, int direction, int ...@@ -2063,9 +2228,11 @@ static int process_class1_cmd(at_state_t *t, void *user_data, int direction, int
s->at_state.dte_is_waiting = TRUE; s->at_state.dte_is_waiting = TRUE;
break; break;
} }
/*endif*/
} }
while (msg[0] == AT_RESPONSE_CODE_CONNECT); while (msg[0] == AT_RESPONSE_CODE_CONNECT);
} }
/*endif*/
immediate_response = FALSE; immediate_response = FALSE;
break; break;
default: default:
...@@ -2158,6 +2325,7 @@ static int process_class1_cmd(at_state_t *t, void *user_data, int direction, int ...@@ -2158,6 +2325,7 @@ static int process_class1_cmd(at_state_t *t, void *user_data, int direction, int
default: default:
return -1; return -1;
} }
/*endswitch*/
span_log(&s->logging, SPAN_LOG_FLOW, "Short training = %d, bit rate = %d\n", s->short_train, s->bit_rate); span_log(&s->logging, SPAN_LOG_FLOW, "Short training = %d, bit rate = %d\n", s->short_train, s->bit_rate);
if (new_transmit) if (new_transmit)
{ {
...@@ -2168,17 +2336,19 @@ static int process_class1_cmd(at_state_t *t, void *user_data, int direction, int ...@@ -2168,17 +2336,19 @@ static int process_class1_cmd(at_state_t *t, void *user_data, int direction, int
{ {
t31_set_at_rx_mode(s, AT_MODE_DELIVERY); t31_set_at_rx_mode(s, AT_MODE_DELIVERY);
} }
/*endif*/
restart_modem(s, new_modem); restart_modem(s, new_modem);
immediate_response = FALSE; immediate_response = FALSE;
break; break;
} }
/*endswitch*/
return immediate_response; return immediate_response;
} }
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/
SPAN_DECLARE(void) t31_call_event(t31_state_t *s, int event) SPAN_DECLARE(void) t31_call_event(t31_state_t *s, int event)
{ {
span_log(&s->logging, SPAN_LOG_FLOW, "Call event %d received\n", event); span_log(&s->logging, SPAN_LOG_FLOW, "Call event %s (%d) received\n", at_call_state_to_str(event), event);
at_call_event(&s->at_state, event); at_call_event(&s->at_state, event);
} }
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/
...@@ -2193,6 +2363,7 @@ SPAN_DECLARE(int) t31_at_rx(t31_state_t *s, const char *t, int len) ...@@ -2193,6 +2363,7 @@ SPAN_DECLARE(int) t31_at_rx(t31_state_t *s, const char *t, int len)
{ {
if (s->dte_data_timeout) if (s->dte_data_timeout)
s->dte_data_timeout = s->call_samples + ms_to_samples(5000); s->dte_data_timeout = s->call_samples + ms_to_samples(5000);
/*endif*/
switch (s->at_state.at_rx_mode) switch (s->at_state.at_rx_mode)
{ {
case AT_MODE_ONHOOK_COMMAND: case AT_MODE_ONHOOK_COMMAND:
...@@ -2209,6 +2380,7 @@ SPAN_DECLARE(int) t31_at_rx(t31_state_t *s, const char *t, int len) ...@@ -2209,6 +2380,7 @@ SPAN_DECLARE(int) t31_at_rx(t31_state_t *s, const char *t, int len)
s->at_state.rx_data[s->at_state.rx_data_bytes++] = ETX; s->at_state.rx_data[s->at_state.rx_data_bytes++] = ETX;
s->at_state.at_tx_handler(&s->at_state, s->at_state.at_tx_user_data, s->at_state.rx_data, s->at_state.rx_data_bytes); s->at_state.at_tx_handler(&s->at_state, s->at_state.at_tx_user_data, s->at_state.rx_data, s->at_state.rx_data_bytes);
} }
/*endif*/
s->at_state.rx_data_bytes = 0; s->at_state.rx_data_bytes = 0;
s->at_state.transmit = FALSE; s->at_state.transmit = FALSE;
s->modem = FAX_MODEM_SILENCE_TX; s->modem = FAX_MODEM_SILENCE_TX;
...@@ -2216,6 +2388,7 @@ SPAN_DECLARE(int) t31_at_rx(t31_state_t *s, const char *t, int len) ...@@ -2216,6 +2388,7 @@ SPAN_DECLARE(int) t31_at_rx(t31_state_t *s, const char *t, int len)
t31_set_at_rx_mode(s, AT_MODE_OFFHOOK_COMMAND); t31_set_at_rx_mode(s, AT_MODE_OFFHOOK_COMMAND);
at_put_response_code(&s->at_state, AT_RESPONSE_CODE_OK); at_put_response_code(&s->at_state, AT_RESPONSE_CODE_OK);
} }
/*endif*/
break; break;
case AT_MODE_HDLC: case AT_MODE_HDLC:
dle_unstuff_hdlc(s, t, len); dle_unstuff_hdlc(s, t, len);
...@@ -2228,12 +2401,14 @@ SPAN_DECLARE(int) t31_at_rx(t31_state_t *s, const char *t, int len) ...@@ -2228,12 +2401,14 @@ SPAN_DECLARE(int) t31_at_rx(t31_state_t *s, const char *t, int len)
memmove(&s->tx.data[0], &s->tx.data[s->tx.out_bytes], s->tx.in_bytes); memmove(&s->tx.data[0], &s->tx.data[s->tx.out_bytes], s->tx.in_bytes);
s->tx.out_bytes = 0; s->tx.out_bytes = 0;
} }
/*endif*/
dle_unstuff(s, t, len); dle_unstuff(s, t, len);
break; break;
case AT_MODE_CONNECTED: case AT_MODE_CONNECTED:
/* TODO: Implement for data modem operation */ /* TODO: Implement for data modem operation */
break; break;
} }
/*endswitch*/
return len; return len;
} }
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/
...@@ -2251,6 +2426,7 @@ static int silence_rx(void *user_data, const int16_t amp[], int len) ...@@ -2251,6 +2426,7 @@ static int silence_rx(void *user_data, const int16_t amp[], int len)
s->audio.silence_heard = 0; s->audio.silence_heard = 0;
s->silence_awaited = 0; s->silence_awaited = 0;
} }
/*endif*/
return 0; return 0;
} }
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/
...@@ -2272,6 +2448,7 @@ static int cng_rx(void *user_data, const int16_t amp[], int len) ...@@ -2272,6 +2448,7 @@ static int cng_rx(void *user_data, const int16_t amp[], int len)
{ {
fsk_rx(&s->audio.modems.v21_rx, amp, len); fsk_rx(&s->audio.modems.v21_rx, amp, len);
} }
/*endif*/
return 0; return 0;
} }
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/
...@@ -2300,8 +2477,11 @@ SPAN_DECLARE_NONSTD(int) t31_rx(t31_state_t *s, int16_t amp[], int len) ...@@ -2300,8 +2477,11 @@ SPAN_DECLARE_NONSTD(int) t31_rx(t31_state_t *s, int16_t amp[], int len)
{ {
if (s->audio.silence_heard <= ms_to_samples(255*10)) if (s->audio.silence_heard <= ms_to_samples(255*10))
s->audio.silence_heard++; s->audio.silence_heard++;
/*endif*/
} }
/*endif*/
} }
/*endfor*/
/* Time is determined by counting the samples in audio packets coming in. */ /* Time is determined by counting the samples in audio packets coming in. */
s->call_samples += len; s->call_samples += len;
...@@ -2315,6 +2495,7 @@ SPAN_DECLARE_NONSTD(int) t31_rx(t31_state_t *s, int16_t amp[], int len) ...@@ -2315,6 +2495,7 @@ SPAN_DECLARE_NONSTD(int) t31_rx(t31_state_t *s, int16_t amp[], int len)
at_put_response_code(&s->at_state, AT_RESPONSE_CODE_ERROR); at_put_response_code(&s->at_state, AT_RESPONSE_CODE_ERROR);
restart_modem(s, FAX_MODEM_SILENCE_TX); restart_modem(s, FAX_MODEM_SILENCE_TX);
} }
/*endif*/
s->audio.modems.rx_handler(s->audio.modems.rx_user_data, amp, len); s->audio.modems.rx_handler(s->audio.modems.rx_user_data, amp, len);
return 0; return 0;
...@@ -2340,6 +2521,7 @@ SPAN_DECLARE_NONSTD(int) t31_rx_fillin(t31_state_t *s, int len) ...@@ -2340,6 +2521,7 @@ SPAN_DECLARE_NONSTD(int) t31_rx_fillin(t31_state_t *s, int len)
at_put_response_code(&s->at_state, AT_RESPONSE_CODE_ERROR); at_put_response_code(&s->at_state, AT_RESPONSE_CODE_ERROR);
restart_modem(s, FAX_MODEM_SILENCE_TX); restart_modem(s, FAX_MODEM_SILENCE_TX);
} }
/*endif*/
s->audio.modems.rx_fillin_handler(s->audio.modems.rx_fillin_user_data, len); s->audio.modems.rx_fillin_handler(s->audio.modems.rx_fillin_user_data, len);
return 0; return 0;
...@@ -2354,6 +2536,7 @@ static int set_next_tx_type(t31_state_t *s) ...@@ -2354,6 +2536,7 @@ static int set_next_tx_type(t31_state_t *s)
fax_modems_set_next_tx_handler(&s->audio.modems, (span_tx_handler_t) NULL, NULL); fax_modems_set_next_tx_handler(&s->audio.modems, (span_tx_handler_t) NULL, NULL);
return 0; return 0;
} }
/*endif*/
/* There is nothing else to change to, so use zero length silence */ /* There is nothing else to change to, so use zero length silence */
silence_gen_alter(&s->audio.modems.silence_gen, 0); silence_gen_alter(&s->audio.modems.silence_gen, 0);
fax_modems_set_tx_handler(&s->audio.modems, (span_tx_handler_t) &silence_gen, &s->audio.modems.silence_gen); fax_modems_set_tx_handler(&s->audio.modems, (span_tx_handler_t) &silence_gen, &s->audio.modems.silence_gen);
...@@ -2375,14 +2558,18 @@ SPAN_DECLARE_NONSTD(int) t31_tx(t31_state_t *s, int16_t amp[], int max_len) ...@@ -2375,14 +2558,18 @@ SPAN_DECLARE_NONSTD(int) t31_tx(t31_state_t *s, int16_t amp[], int max_len)
set_next_tx_type(s); set_next_tx_type(s);
if ((len += s->audio.modems.tx_handler(s->audio.modems.tx_user_data, amp + len, max_len - len)) < max_len) if ((len += s->audio.modems.tx_handler(s->audio.modems.tx_user_data, amp + len, max_len - len)) < max_len)
front_end_status(s, T30_FRONT_END_SEND_STEP_COMPLETE); front_end_status(s, T30_FRONT_END_SEND_STEP_COMPLETE);
/*endif*/
} }
/*endif*/
} }
/*endif*/
if (s->audio.modems.transmit_on_idle) if (s->audio.modems.transmit_on_idle)
{ {
/* Pad to the requested length with silence */ /* Pad to the requested length with silence */
memset(amp + len, 0, (max_len - len)*sizeof(int16_t)); memset(amp + len, 0, (max_len - len)*sizeof(int16_t));
len = max_len; len = max_len;
} }
/*endif*/
return len; return len;
} }
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/
...@@ -2422,6 +2609,7 @@ SPAN_DECLARE(void) t31_set_t38_config(t31_state_t *s, int without_pacing) ...@@ -2422,6 +2609,7 @@ SPAN_DECLARE(void) t31_set_t38_config(t31_state_t *s, int without_pacing)
t38_set_redundancy_control(&s->t38_fe.t38, T38_PACKET_CATEGORY_IMAGE_DATA_END, DATA_END_TX_COUNT); t38_set_redundancy_control(&s->t38_fe.t38, T38_PACKET_CATEGORY_IMAGE_DATA_END, DATA_END_TX_COUNT);
s->t38_fe.ms_per_tx_chunk = MS_PER_TX_CHUNK; s->t38_fe.ms_per_tx_chunk = MS_PER_TX_CHUNK;
} }
/*endif*/
set_octets_per_data_packet(s, 300); set_octets_per_data_packet(s, 300);
} }
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/
...@@ -2491,14 +2679,17 @@ SPAN_DECLARE(t31_state_t *) t31_init(t31_state_t *s, ...@@ -2491,14 +2679,17 @@ SPAN_DECLARE(t31_state_t *) t31_init(t31_state_t *s,
if (at_tx_handler == NULL || modem_control_handler == NULL) if (at_tx_handler == NULL || modem_control_handler == NULL)
return NULL; return NULL;
/*endif*/
alloced = FALSE; alloced = FALSE;
if (s == NULL) if (s == NULL)
{ {
if ((s = (t31_state_t *) malloc(sizeof (*s))) == NULL) if ((s = (t31_state_t *) malloc(sizeof (*s))) == NULL)
return NULL; return NULL;
/*endif*/
alloced = TRUE; alloced = TRUE;
} }
/*endif*/
memset(s, 0, sizeof(*s)); memset(s, 0, sizeof(*s));
span_log_init(&s->logging, SPAN_LOG_NONE, NULL); span_log_init(&s->logging, SPAN_LOG_NONE, NULL);
span_log_set_protocol(&s->logging, "T.31"); span_log_set_protocol(&s->logging, "T.31");
...@@ -2549,8 +2740,10 @@ SPAN_DECLARE(t31_state_t *) t31_init(t31_state_t *s, ...@@ -2549,8 +2740,10 @@ SPAN_DECLARE(t31_state_t *) t31_init(t31_state_t *s,
{ {
if (alloced) if (alloced)
free(s); free(s);
/*endif*/
return NULL; return NULL;
} }
/*endif*/
at_init(&s->at_state, at_tx_handler, at_tx_user_data, t31_modem_control_handler, s); at_init(&s->at_state, at_tx_handler, at_tx_user_data, t31_modem_control_handler, s);
at_set_class1_handler(&s->at_state, process_class1_cmd, s); at_set_class1_handler(&s->at_state, process_class1_cmd, s);
s->at_state.dte_inactivity_timeout = DEFAULT_DTE_TIMEOUT; s->at_state.dte_inactivity_timeout = DEFAULT_DTE_TIMEOUT;
...@@ -2559,6 +2752,7 @@ SPAN_DECLARE(t31_state_t *) t31_init(t31_state_t *s, ...@@ -2559,6 +2752,7 @@ SPAN_DECLARE(t31_state_t *) t31_init(t31_state_t *s,
t31_t38_fe_init(s, tx_t38_packet_handler, tx_t38_packet_user_data); t31_t38_fe_init(s, tx_t38_packet_handler, tx_t38_packet_user_data);
t31_set_t38_config(s, FALSE); t31_set_t38_config(s, FALSE);
} }
/*endif*/
s->t38_mode = FALSE; s->t38_mode = FALSE;
return s; return s;
} }
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论