372
372
enum ast_t38_state t38_state;
373
373
struct ast_control_t38_parameters t38_parameters = { .version = 0,
375
.rate = AST_T38_RATE_9600,
375
.rate = AST_T38_RATE_14400,
376
376
.rate_management = AST_T38_RATE_MANAGEMENT_TRANSFERRED_TCF,
377
377
.fill_bit_removal = 1,
378
378
.transcoding_mmr = 1,
379
379
.transcoding_jbig = 1,
382
/* if in receive mode, try to use T.38 */
382
/* if in called party mode, try to use T.38 */
383
if (s->caller_mode == FALSE) {
384
384
/* check if we are already in T.38 mode (unlikely), or if we can request
385
385
* a switch... if so, request it now and wait for the result, rather
386
386
* than starting an audio FAX session that will have to be cancelled
492
492
while (!s->finished) {
495
if ((res = ast_waitfor(s->chan, 20)) < 0) {
499
/* if nothing arrived, check the watchdog timers */
502
if (ast_tvdiff_sec(now, start) > WATCHDOG_TOTAL_TIMEOUT || ast_tvdiff_sec(now, state_change) > WATCHDOG_STATE_TIMEOUT) {
503
ast_log(LOG_WARNING, "It looks like we hung. Aborting.\n");
507
/* timers have not triggered, loop around to wait
495
if ((res = ast_waitfor(s->chan, 25)) < 0) {
496
ast_debug(1, "Error waiting for a frame\n");
502
if (ast_tvdiff_sec(now, start) > WATCHDOG_TOTAL_TIMEOUT || ast_tvdiff_sec(now, state_change) > WATCHDOG_STATE_TIMEOUT) {
503
ast_log(LOG_WARNING, "It looks like we hung. Aborting.\n");
509
/* There was timeout waiting for a frame. Loop around and wait again */
513
/* There is a frame available. Get it */
514
516
if (!(inf = ast_read(s->chan))) {
515
517
ast_debug(1, "Channel hangup\n");
613
615
memset(&t38, 0, sizeof(t38));
614
616
if (t38_terminal_init(&t38, s->caller_mode, t38_tx_packet_handler, s->chan) == NULL) {
615
617
ast_log(LOG_WARNING, "Unable to start T.38 termination.\n");
619
622
t38_set_max_datagram_size(t38state, s->t38parameters.max_ifp);
700
703
t30_terminate(t30state);
701
704
t38_terminal_release(&t38);
707
/* if we are not the caller, it's our job to shut down the T.38
708
* session when the FAX transmisson is complete.
710
if ((s->caller_mode == FALSE) &&
711
(ast_channel_get_t38_state(s->chan) == T38_STATE_NEGOTIATED)) {
712
struct ast_control_t38_parameters t38_parameters = { .request_response = AST_T38_REQUEST_TERMINATE, };
714
if (ast_indicate_data(s->chan, AST_CONTROL_T38_PARAMETERS, &t38_parameters, sizeof(t38_parameters)) == 0) {
715
/* wait up to five seconds for negotiation to complete */
716
unsigned int timeout = 5000;
719
ast_debug(1, "Shutting down T.38 on %s\n", s->chan->name);
720
while (timeout > 0) {
721
ms = ast_waitfor(s->chan, 1000);
723
ast_log(LOG_WARNING, "something bad happened while channel '%s' was polling.\n", s->chan->name);
727
/* nothing happened */
732
ast_log(LOG_WARNING, "channel '%s' timed-out during the T.38 shutdown.\n", s->chan->name);
736
if (!(inf = ast_read(s->chan))) {
739
if ((inf->frametype == AST_FRAME_CONTROL) &&
740
(inf->subclass == AST_CONTROL_T38_PARAMETERS) &&
741
(inf->datalen == sizeof(t38_parameters))) {
742
struct ast_control_t38_parameters *parameters = inf->data.ptr;
744
switch (parameters->request_response) {
745
case AST_T38_TERMINATED:
746
ast_debug(1, "Shut down T.38 on %s\n", s->chan->name);
748
case AST_T38_REFUSED:
749
ast_log(LOG_WARNING, "channel '%s' refused to disable T.38\n", s->chan->name);
752
ast_log(LOG_ERROR, "channel '%s' failed to disable T.38\n", s->chan->name);