]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
Better handling of bad HDLC frames in T.38 gateway operation.
authorSteve Underwood <steveu@coppice.org>
Fri, 18 Jul 2014 02:29:23 +0000 (10:29 +0800)
committerSteve Underwood <steveu@coppice.org>
Fri, 18 Jul 2014 02:29:23 +0000 (10:29 +0800)
libs/spandsp/src/t38_gateway.c
libs/spandsp/tests/fax_tests.c
libs/spandsp/tests/v22bis_tests.c

index 2a9e41b74c1f0a6f5391c4b1cde966ccabb67227..bb3d02e9024e3bae4ff0bbc6c8dc54c004506541 100644 (file)
@@ -1914,7 +1914,7 @@ static void t38_hdlc_rx_put_bit(hdlc_rx_state_t *t, int new_bit)
     }
     /*endif*/
     t->num_bits++;
-    if (!t->framing_ok_announced)
+    if (t->flags_seen < t->framing_ok_threshold)
         return;
     /*endif*/
     t->byte_in_progress = (t->byte_in_progress >> 1) | ((t->raw_bit_stream & 0x01) << 7);
@@ -1922,17 +1922,26 @@ static void t38_hdlc_rx_put_bit(hdlc_rx_state_t *t, int new_bit)
         return;
     /*endif*/
     t->num_bits = 0;
+    s = (t38_gateway_state_t *) t->frame_user_data;
+    u = &s->core.to_t38;
     if (t->len >= (int) sizeof(t->buffer))
     {
         /* This is too long. Abandon the frame, and wait for the next flag octet. */
+        if ((t->len + 2) >= u->octets_per_data_packet)
+        {
+            /* We will have sent some of this frame already, so we need to send termination of this bad HDLC frame. */
+            category = (s->t38x.current_tx_data_type == T38_DATA_V21)  ?  T38_PACKET_CATEGORY_CONTROL_DATA  :  T38_PACKET_CATEGORY_IMAGE_DATA;
+            if (t38_core_send_data(&s->t38x.t38, s->t38x.current_tx_data_type, T38_FIELD_HDLC_FCS_BAD, NULL, 0, category) < 0)
+                span_log(&s->logging, SPAN_LOG_WARNING, "T.38 send failed\n");
+            /*endif*/
+        }
+        /*endif*/
         t->rx_length_errors++;
         t->flags_seen = t->framing_ok_threshold - 1;
         t->len = 0;
         return;
     }
     /*endif*/
-    s = (t38_gateway_state_t *) t->frame_user_data;
-    u = &s->core.to_t38;
     t->buffer[t->len] = (uint8_t) t->byte_in_progress;
     if (t->len == 1)
     {
@@ -1969,7 +1978,7 @@ static void t38_hdlc_rx_put_bit(hdlc_rx_state_t *t, int new_bit)
     }
     if (++u->data_ptr >= u->octets_per_data_packet)
     {
-        bit_reverse(u->data, t->buffer + t->len - 2 - u->data_ptr, u->data_ptr);
+        bit_reverse(u->data, &t->buffer[t->len - 2 - u->data_ptr], u->data_ptr);
         category = (s->t38x.current_tx_data_type == T38_DATA_V21)  ?  T38_PACKET_CATEGORY_CONTROL_DATA  :  T38_PACKET_CATEGORY_IMAGE_DATA;
         if (t38_core_send_data(&s->t38x.t38, s->t38x.current_tx_data_type, T38_FIELD_HDLC_DATA, u->data, u->data_ptr, category) < 0)
             span_log(&s->logging, SPAN_LOG_WARNING, "T.38 send failed\n");
index 9dbf6ce4e6cfa5c4287d098016e2019467d68586..f3b34b91a3016ed1a901191bd46a10c4bd48ea50 100644 (file)
@@ -420,8 +420,7 @@ static void set_t30_callbacks(t30_state_t *t30, int chan)
 }
 /*- End of function --------------------------------------------------------*/
 
-static void real_time_gateway_frame_handler(t38_gateway_state_t *s,
-                                            void *user_data,
+static void real_time_gateway_frame_handler(void *user_data,
                                             bool incoming,
                                             const uint8_t *msg,
                                             int len)
index d42b2f4f4da36c215bf9f0c787774401a0557dc6..f3c0532e9219d549855a248133e2c2c18644f952 100644 (file)
@@ -263,11 +263,11 @@ int main(int argc, char *argv[])
     int j;
     int test_bps;
     int line_model_no;
+    int channel_codec;
+    int rbs_pattern;
     int bits_per_test;
     int noise_level;
     int signal_level;
-    int channel_codec;
-    int rbs_pattern;
     int guard_tone_option;
     int opt;
     bool log_audio;