diff -durN asterisk-1.2.25/channels/chan_zap.c asterisk-1.2.25-test/debian/build/asterisk-bristuff/channels/chan_zap.c --- asterisk-1.2.25/channels/chan_zap.c 2008-03-05 19:57:46.000000000 +0000 +++ asterisk-1.2.25-test/channels/chan_zap.c 2008-04-09 18:19:03.000000000 +0100 @@ -562,6 +562,7 @@ int busy_quietlength; int callprogress; + int waitfordialtone; char accountcode[AST_MAX_ACCOUNT_CODE]; @@ -682,6 +683,7 @@ .busy_quietlength = 0, .callprogress = 0, + .waitfordialtone = 0, .accountcode = "", @@ -863,6 +865,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 */ @@ -2114,6 +2118,7 @@ return -1; } p->dialednone = 0; + p->waitingfordt.tv_sec = 0; if (p->radio) /* if a radio channel, up immediately */ { /* Special pseudo -- automatically up */ @@ -2334,6 +2339,20 @@ 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; @@ -3036,6 +3055,7 @@ p->callwaiting = p->permcallwaiting; p->hidecallerid = p->permhidecallerid; p->dialing = 0; + p->waitingfordt.tv_sec = 0; p->rdnis[0] = '\0'; update_conf(p); reset_conf(p); @@ -4705,14 +4725,15 @@ case SIG_SF_FEATDMF: case SIG_SF_FEATB: /* FGD MF *Must* wait for wink */ - if (!ast_strlen_zero(p->dop.dialstr)) + if (!ast_strlen_zero(p->dop.dialstr)) { res = ioctl(p->subs[SUB_REAL].zfd, ZT_DIAL, &p->dop); - else 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); + 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->dop.dialstr[0] = '\0'; break; default: @@ -4722,6 +4743,7 @@ case ZT_EVENT_HOOKCOMPLETE: if (p->inalarm) break; if (p->radio) break; + if (p->waitingfordt.tv_sec) break; switch(p->sig) { case SIG_FXSLS: /* only interesting for FXS */ case SIG_FXSGS: @@ -4733,14 +4755,15 @@ case SIG_SF: case SIG_SFWINK: case SIG_SF_FEATD: - if (!ast_strlen_zero(p->dop.dialstr)) + if (!ast_strlen_zero(p->dop.dialstr)) { res = ioctl(p->subs[SUB_REAL].zfd, ZT_DIAL, &p->dop); - else 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); + 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->dop.dialstr[0] = '\0'; p->dop.op = ZT_DIAL_OP_REPLACE; break; @@ -5150,7 +5173,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) { @@ -5171,6 +5194,37 @@ #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) { + /* Got 10 chunks of dialtone... */ + 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 @@ -5530,6 +5584,9 @@ 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; @@ -7744,6 +7801,7 @@ tmp->busy_tonelength = chan_conf.busy_tonelength; tmp->busy_quietlength = chan_conf.busy_quietlength; tmp->callprogress = chan_conf.callprogress; + tmp->waitfordialtone = chan_conf.waitfordialtone; tmp->cancallforward = chan_conf.cancallforward; tmp->dtmfrelax = chan_conf.relaxdtmf; tmp->callwaiting = tmp->permcallwaiting; @@ -12401,6 +12459,8 @@ chan_conf.callprogress |= 1; else chan_conf.callprogress &= ~1; + } else if (!strcasecmp(v->name, "waitfordialtone")) { + chan_conf.waitfordialtone = atoi(v->value); } else if (!strcasecmp(v->name, "faxdetect")) { if (!strcasecmp(v->value, "incoming")) { chan_conf.callprogress |= 4; diff -durN asterisk-1.2.25/dsp.c asterisk-1.2.25-test/debian/build/asterisk-bristuff/dsp.c --- asterisk-1.2.25/dsp.c 2007-03-08 16:04:58.000000000 +0000 +++ asterisk-1.2.25-test/dsp.c 2008-04-09 18:12:35.000000000 +0100 @@ -79,7 +79,9 @@ #define HZ_425 0 /* For UK mode */ -#define HZ_400 0 +#define HZ_350UK 0 +#define HZ_400UK 1 +#define HZ_440UK 2 static struct progalias { char *name; @@ -98,7 +100,7 @@ } modes[] = { { GSAMP_SIZE_NA, { 350, 440, 480, 620, 950, 1400, 1800 } }, /* North America */ { GSAMP_SIZE_CR, { 425 } }, - { GSAMP_SIZE_UK, { 400 } }, + { GSAMP_SIZE_UK, { 350, 400, 440 } }, }; #define DEFAULT_THRESHOLD 512 @@ -1054,9 +1056,9 @@ for (y=0;y<7;y++) hz[y] = goertzel_result(&dsp->freqs[y]); #if 0 - printf("\n350: 425: 440: 480: 620: 950: 1400: 1800: Energy: \n"); - printf("%.2e %.2e %.2e %.2e %.2e %.2e %.2e %.2e %.2e\n", - hz[HZ_350], hz[HZ_425], hz[HZ_440], hz[HZ_480], hz[HZ_620], hz[HZ_950], hz[HZ_1400], hz[HZ_1800], dsp->genergy); + printf("\n350: 425: 440: 480: 620: 950: 1400: 1800: Energy: Progmode:\n"); + printf("%.2e %.2e %.2e %.2e %.2e %.2e %.2e %.2e %.2e %d\n", + hz[HZ_350], hz[HZ_425], hz[HZ_440], hz[HZ_480], hz[HZ_620], hz[HZ_950], hz[HZ_1400], hz[HZ_1800], dsp->genergy, dsp->progmode); #endif switch(dsp->progmode) { case PROG_MODE_NA: @@ -1088,8 +1090,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: @@ -1553,7 +1557,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; } diff -durN asterisk-1.2.25/include/asterisk/dsp.h asterisk-1.2.25-test/debian/build/asterisk-bristuff/include/asterisk/dsp.h --- asterisk-1.2.25/include/asterisk/dsp.h 2005-11-29 18:24:39.000000000 +0000 +++ asterisk-1.2.25-test/include/asterisk/dsp.h 2008-04-09 18:24:35.000000000 +0100 @@ -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