Index: chan_zap.c =================================================================== RCS file: /usr/cvsroot/asterisk/channels/chan_zap.c,v retrieving revision 1.421 diff -u -r1.421 chan_zap.c --- chan_zap.c 27 Mar 2005 22:48:55 -0000 1.421 +++ chan_zap.c 28 Mar 2005 17:22:06 -0000 @@ -281,6 +281,9 @@ /* Whether we hang up on a Polarity Switch event */ static int hanguponpolarityswitch = 0; +/* Set polarity=IDLE whenever we get a RING event */ +static int resetpolarityonring = 0; + /* How long (ms) to ignore Polarity Switch events after we answer a call */ static int polarityonanswerdelay = 600; @@ -586,6 +589,7 @@ int emdigitwait; int answeronpolarityswitch; int hanguponpolarityswitch; + int resetpolarityonring; int polarityonanswerdelay; struct timeval polaritydelaytv; int sendcalleridafter; @@ -3547,12 +3551,15 @@ p->ringt = RINGT; } - /* If we get a ring then we cannot be in - * reversed polarity. So we reset to idle */ + if (p->resetpolarityonring) { + /* Since the polarity detector didn't always + * detect a reversal before a ring, we reset + * to idle. Sweden-specific? */ ast_log(LOG_DEBUG, "Setting IDLE polarity due " "to ring. Old polarity was %d\n", p->polarity); p->polarity = POLARITY_IDLE; + } /* Fall through */ case SIG_EM: @@ -3858,12 +3865,14 @@ (ast->_state == AST_STATE_RINGING))) { ast_log(LOG_DEBUG, "Answering on polarity switch!\n"); ast_setstate(p->owner, AST_STATE_UP); + gettimeofday(&p->polaritydelaytv,NULL); } else ast_log(LOG_DEBUG, "Ignore switch to REVERSED Polarity on channel %d, state %d\n", p->channel, ast->_state); } else if(p->hanguponpolarityswitch && (p->polarityonanswerdelay > 0) && (p->polarity == POLARITY_REV) && - (ast->_state == AST_STATE_UP)) { + (ast->_state == AST_STATE_UP || + ast->_state == AST_STATE_RING)) { struct timeval tv; gettimeofday(&tv, NULL); @@ -3872,7 +3881,7 @@ ast_softhangup(p->owner, AST_SOFTHANGUP_EXPLICIT); p->polarity = POLARITY_IDLE; } else { - ast_log(LOG_DEBUG, "Ignore Reverse Polarity (too close to answer event) on channel %d, state %d\n", p->channel, ast->_state); + ast_log(LOG_DEBUG, "Ignore Reverse Polarity (too close to previous event) on channel %d, state %d\n", p->channel, ast->_state); } } else { p->polarity = POLARITY_IDLE; @@ -5741,6 +5750,12 @@ if (res < 0) { ast_log(LOG_WARNING, "CallerID returned with error on channel '%s'\n", chan->name); } + /* We should have got a polarity reversal + * but it was not handled ?? */ + if (p->hanguponpolarityswitch) { + p->polarity=POLARITY_REV; + gettimeofday(&p->polaritydelaytv,NULL); + } } else ast_log(LOG_WARNING, "Unable to get caller ID space\n"); } @@ -6813,6 +6828,7 @@ tmp->polarityonanswerdelay = polarityonanswerdelay; tmp->answeronpolarityswitch = answeronpolarityswitch; tmp->hanguponpolarityswitch = hanguponpolarityswitch; + tmp->resetpolarityonring = resetpolarityonring; tmp->sendcalleridafter = sendcalleridafter; } @@ -10094,7 +10110,9 @@ hanguponpolarityswitch = ast_true(v->value); } else if (!strcasecmp(v->name, "sendcalleridafter")) { sendcalleridafter = atoi(v->value); - } + } else if (!strcasecmp(v->name, "resetpolarityonring")) { + resetpolarityonring = ast_true(v->value); + } } else ast_log(LOG_WARNING, "Ignoring %s\n", v->name); v = v->next;