Index: channels/chan_zap.c =================================================================== --- channels/chan_zap.c (revision 113295) +++ channels/chan_zap.c (working copy) @@ -543,6 +543,8 @@ int busy_tonelength; int busy_quietlength; int callprogress; + int waitfordialtone; + struct timeval waitingfordt; /*!< Time we started waiting for dialtone */ struct timeval flashtime; /*!< Last flash-hook time */ struct ast_dsp *dsp; int cref; /*!< Call reference number */ @@ -1796,6 +1798,7 @@ ast_mutex_unlock(&p->lock); return -1; } + p->waitingfordt.tv_sec = 0; p->dialednone = 0; if ((p->radio || (p->oprmode < 0))) /* if a radio channel, up immediately */ { @@ -2019,6 +2022,21 @@ p->dop.dialstr[strlen(p->dop.dialstr)-2] = '\0'; } else p->echobreak = 0; + + /* waitfordialtone ? */ +#ifdef ZAPATA_PRI + if (!p->pri) { +#endif + if( p->waitfordialtone && CANPROGRESSDETECT(p) && p->dsp ) { + ast_log(LOG_DEBUG, "Defer dialling for %dms or dialtone\n", p->waitfordialtone); + gettimeofday(&p->waitingfordt,NULL); + ast_setstate(ast, AST_STATE_OFFHOOK); + break; + } +#ifdef ZAPATA_PRI + } +#endif + if (!res) { if (ioctl(p->subs[SUB_REAL].zfd, ZT_DIAL, &p->dop)) { x = ZT_ONHOOK; @@ -2685,6 +2703,7 @@ p->callwaitcas = 0; p->callwaiting = p->permcallwaiting; p->hidecallerid = p->permhidecallerid; + p->waitingfordt.tv_sec = 0; p->dialing = 0; p->rdnis[0] = '\0'; update_conf(p); @@ -4430,6 +4449,7 @@ case ZT_EVENT_HOOKCOMPLETE: if (p->inalarm) break; if ((p->radio || (p->oprmode < 0))) break; + if (p->waitingfordt.tv_sec) break; switch (mysig) { case SIG_FXSLS: /* only interesting for FXS */ case SIG_FXSGS: @@ -4884,7 +4904,7 @@ p->subs[index].f.data = NULL; p->subs[index].f.datalen= 0; } - if (p->dsp && (!p->ignoredtmf || p->callwaitcas || p->busydetect || p->callprogress) && !index) { + if (p->dsp && (!p->ignoredtmf || p->callwaitcas || p->busydetect || p->callprogress || p->waitingfordt.tv_sec) && !index) { /* Perform busy detection. etc on the zap line */ f = ast_dsp_process(ast, p->dsp, &p->subs[index].f); if (f) { @@ -4904,6 +4924,36 @@ #endif /* DSP clears us of being pulse */ p->pulsedial = 0; + } else if (p->waitingfordt.tv_sec) { + if (ast_tvdiff_ms(ast_tvnow(), p->waitingfordt) >= p->waitfordialtone ) { + p->waitingfordt.tv_sec = 0; + ast_log(LOG_WARNING, "Never saw dialtone on channel %d\n", p->channel); + f=NULL; + } else if (f->frametype == AST_FRAME_VOICE) { + f->frametype = AST_FRAME_NULL; + f->subclass = 0; + if (ast_dsp_get_tstate(p->dsp) == DSP_TONE_STATE_DIALTONE && ast_dsp_get_tcount(p->dsp) > 9) { + p->waitingfordt.tv_sec = 0; + p->dsp_features &= ~DSP_FEATURE_WAITDIALTONE; + ast_dsp_set_features(p->dsp, p->dsp_features); + ast_log(LOG_DEBUG, "Got 10 samples of dialtone!\n"); + if (!ast_strlen_zero(p->dop.dialstr)) { /* Dial deferred digits */ + res = ioctl(p->subs[SUB_REAL].zfd, ZT_DIAL, &p->dop); + if (res < 0) { + ast_log(LOG_WARNING, "Unable to initiate dialing on trunk channel %d\n", p-> +channel); + p->dop.dialstr[0] = '\0'; + return NULL; + } else { + ast_log(LOG_DEBUG, "Sent deferred digit string: %s\n", p->dop.dialstr); + p->dialing = 1; + p->dop.dialstr[0] = '\0'; + p->dop.op = ZT_DIAL_OP_REPLACE; + ast_setstate(ast, AST_STATE_DIALING); + } + } + } + } } } } else @@ -5269,6 +5319,8 @@ features |= DSP_FEATURE_BUSY_DETECT; if ((i->callprogress & 1) && CANPROGRESSDETECT(i)) features |= DSP_FEATURE_CALL_PROGRESS; + if ((i->waitfordialtone) && CANPROGRESSDETECT(i)) + features |= DSP_FEATURE_WAITDIALTONE; if ((!i->outgoing && (i->callprogress & 4)) || (i->outgoing && (i->callprogress & 2))) { features |= DSP_FEATURE_FAX_DETECT; @@ -7471,6 +7523,7 @@ tmp->busy_tonelength = conf.chan.busy_tonelength; tmp->busy_quietlength = conf.chan.busy_quietlength; tmp->callprogress = conf.chan.callprogress; + tmp->waitfordialtone = conf.chan.waitfordialtone; tmp->cancallforward = conf.chan.cancallforward; tmp->dtmfrelax = conf.chan.dtmfrelax; tmp->callwaiting = tmp->permcallwaiting; @@ -10697,6 +10750,8 @@ confp->chan.callprogress |= 1; else confp->chan.callprogress &= ~1; + } else if (!strcasecmp(v->name, "waitfordialtone")) { + confp->chan.waitfordialtone = atoi(v->value); } else if (!strcasecmp(v->name, "faxdetect")) { if (!strcasecmp(v->value, "incoming")) { confp->chan.callprogress |= 4; Index: include/asterisk/dsp.h =================================================================== --- include/asterisk/dsp.h (revision 113295) +++ include/asterisk/dsp.h (working copy) @@ -41,6 +41,7 @@ #define DSP_PROGRESS_BUSY (1 << 18) /* Enable busy tone detection */ #define DSP_PROGRESS_CONGESTION (1 << 19) /* Enable congestion tone detection */ #define DSP_FEATURE_CALL_PROGRESS (DSP_PROGRESS_TALK | DSP_PROGRESS_RINGING | DSP_PROGRESS_BUSY | DSP_PROGRESS_CONGESTION) +#define DSP_FEATURE_WAITDIALTONE (1 << 20) /* Enable dial tone detection */ #define DSP_TONE_STATE_SILENCE 0 #define DSP_TONE_STATE_RINGING 1 Index: main/dsp.c =================================================================== --- main/dsp.c (revision 113295) +++ main/dsp.c (working copy) @@ -87,7 +87,9 @@ HZ_425 = 0, /*! For UK mode */ - HZ_400 = 0 + HZ_350UK = 0, + HZ_400UK, + HZ_440UK }; static struct progalias { @@ -107,7 +109,7 @@ } modes[] = { { GSAMP_SIZE_NA, { 350, 440, 480, 620, 950, 1400, 1800 } }, /*!< North America */ { GSAMP_SIZE_CR, { 425 } }, /*!< Costa Rica, Brazil */ - { GSAMP_SIZE_UK, { 400 } }, /*!< UK */ + { GSAMP_SIZE_UK, { 350, 400, 440 } }, /*!< UK */ }; #define DEFAULT_THRESHOLD 512 @@ -1126,8 +1128,10 @@ newstate = DSP_TONE_STATE_SILENCE; break; case PROG_MODE_UK: - if (hz[HZ_400] > TONE_MIN_THRESH * TONE_THRESH) { + if (hz[HZ_400UK] > TONE_MIN_THRESH * TONE_THRESH) { newstate = DSP_TONE_STATE_HUNGUP; + } else if (pair_there(hz[HZ_350UK], hz[HZ_440UK], hz[HZ_400UK], hz[HZ_400UK], dsp->genergy)) { + newstate = DSP_TONE_STATE_DIALTONE; } break; default: @@ -1613,7 +1617,9 @@ ast_log(LOG_WARNING, "Don't know how to represent call progress message %d\n", res); } } - } + } else if ((dsp->features & DSP_FEATURE_WAITDIALTONE)) + res = __ast_dsp_call_progress(dsp, shortdata, len); + FIX_INF(af); return af; }