Index: chan_zap.c =================================================================== RCS file: /usr/cvsroot/asterisk/channels/chan_zap.c,v retrieving revision 1.344.2.15 diff -u -r1.344.2.15 chan_zap.c --- chan_zap.c 15 Apr 2005 07:15:39 -0000 1.344.2.15 +++ chan_zap.c 17 May 2005 17:51:43 -0000 @@ -215,6 +215,10 @@ static int busycount = 3; +static int answeronpolarityswitch = 0; + +static int hanguponpolarityswitch = 0; + static int callprogress = 0; static char accountcode[20] = ""; @@ -389,6 +393,9 @@ #define SUB_CALLWAIT 1 /* Call-Waiting call on hold */ #define SUB_THREEWAY 2 /* Three-way call */ +#define POLARITY_IDLE 0 +#define POLARITY_REV 1 + static struct zt_distRings drings; @@ -483,6 +490,7 @@ int cid_signalling; /* CID signalling type bell202 or v23 */ int cid_start; /* CID start indicator, polarity or ring */ int hidecallerid; + int polarity; int callreturn; int permhidecallerid; /* Whether to hide our outgoing caller ID or not */ int restrictcid; /* Whether restrict the callerid -> only send ANI */ @@ -514,6 +522,8 @@ int dnd; int busydetect; int busycount; + int answeronpolarityswitch; + int hanguponpolarityswitch; int callprogress; int priindication_oob; struct timeval flashtime; /* Last flash-hook time */ @@ -846,6 +856,7 @@ p->subs[x].chan = 0; p->subs[x].owner = NULL; p->subs[x].inthreeway = 0; + p->polarity = POLARITY_IDLE; memset(&p->subs[x].curconf, 0, sizeof(p->subs[x].curconf)); return 0; } @@ -1991,6 +2002,7 @@ p->subs[index].linear = 0; p->subs[index].needcallerid = 0; zt_setlinear(p->subs[index].zfd, 0); + p->polarity = POLARITY_IDLE; if (index == SUB_REAL) { if ((p->subs[SUB_CALLWAIT].zfd > -1) && (p->subs[SUB_THREEWAY].zfd > -1)) { ast_log(LOG_DEBUG, "Normal call hung up with both three way call and a call waiting call in place?\n"); @@ -3145,10 +3157,13 @@ ast_log(LOG_DEBUG, "Done dialing, but waiting for progress detection before doing more...\n"); } else if (p->confirmanswer || (!p->dialednone && ((p->sig == SIG_EM) || (p->sig == SIG_EM_E1) || (p->sig == SIG_EMWINK) || (p->sig == SIG_FEATD) || (p->sig == SIG_FEATDMF) || (p->sig == SIG_E911) || (p->sig == SIG_FEATB) || (p->sig == SIG_SF) || (p->sig == SIG_SFWINK) || (p->sig == SIG_SF_FEATD) || (p->sig == SIG_SF_FEATDMF) || (p->sig == SIG_SF_FEATB)))) { ast_setstate(ast, AST_STATE_RINGING); - } else { + } else if (!p->answeronpolarityswitch) { ast_setstate(ast, AST_STATE_UP); p->subs[index].f.frametype = AST_FRAME_CONTROL; p->subs[index].f.subclass = AST_CONTROL_ANSWER; + p->polarity=POLARITY_IDLE; + } else { + p->polarity=POLARITY_IDLE; } } } @@ -3665,6 +3680,28 @@ break; } break; + case ZT_EVENT_POLARITY: + if ( p->hanguponpolarityswitch && + p->polarity == POLARITY_REV && + ( ast->_state == AST_STATE_UP || + ast->_state == AST_STATE_RING )) { + //hangup + ast_log(LOG_VERBOSE, "Hangup due to Reverse Polarity on channel %d\n", p->channel); + ast_softhangup(p->owner, AST_SOFTHANGUP_EXPLICIT); + } else if (p->answeronpolarityswitch && + p->polarity==POLARITY_IDLE && + (ast->_state == AST_STATE_DIALING || + ast->_state == AST_STATE_RINGING)) { + //answer + ast_log(LOG_VERBOSE, "Answering on polarity switch on channel %d\n", p->channel); + p->subs[index].f.frametype = AST_FRAME_CONTROL; + p->subs[index].f.subclass = AST_CONTROL_ANSWER; + ast_setstate(p->owner, AST_STATE_UP); + p->polarity=POLARITY_REV; + } else { + ast_log(LOG_VERBOSE, "Ignoring polarity switch on channel %d. Polarity is unchanged (%s)\n",p->channel,p->polarity==POLARITY_IDLE?"POLARITY_IDLE":"POLARITY_REV"); + } + break; default: ast_log(LOG_DEBUG, "Dunno what to do with event %d on channel %d\n", res, p->channel); } @@ -5704,6 +5741,7 @@ case SIG_FXSLS: case SIG_FXSKS: case SIG_FXSGS: + i->polarity=POLARITY_REV; if (i->cid_start == CID_START_POLARITY) { ast_verbose(VERBOSE_PREFIX_2 "Starting post polarity " "CID detection on channel %d\n", @@ -6460,6 +6498,8 @@ tmp->echocanbridged = echocanbridged; tmp->busydetect = busydetect; tmp->busycount = busycount; + tmp->answeronpolarityswitch = answeronpolarityswitch; + tmp->hanguponpolarityswitch = hanguponpolarityswitch; tmp->callprogress = callprogress; tmp->cancallforward = cancallforward; tmp->dtmfrelax = relaxdtmf; @@ -6470,6 +6510,7 @@ tmp->use_callerid = use_callerid; tmp->cid_signalling = cid_signalling; tmp->cid_start = cid_start; + tmp->polarity = POLARITY_IDLE; tmp->zaptrcallerid = zaptrcallerid; tmp->restrictcid = restrictcid; tmp->use_callingpres = use_callingpres; @@ -9222,6 +9263,10 @@ callprogress |= 1; else callprogress &= ~1; + } else if (!strcasecmp(v->name, "answeronpolarityswitch")) { + answeronpolarityswitch = ast_true(v->value); + } else if (!strcasecmp(v->name, "hanguponpolarityswitch")) { + hanguponpolarityswitch = ast_true(v->value); } else if (!strcasecmp(v->name, "faxdetect")) { if (!strcasecmp(v->value, "incoming")) { callprogress |= 4;