Index: channels/chan_zap.c =================================================================== --- channels/chan_zap.c (revision 62036) +++ channels/chan_zap.c (working copy) @@ -3763,6 +3763,11 @@ ast_setstate(ast, AST_STATE_UP); p->subs[index].f.frametype = AST_FRAME_CONTROL; p->subs[index].f.subclass = AST_CONTROL_ANSWER; + /* If aops=0 and hops=1, this is necessary */ + p->polarity=POLARITY_REV; + } else { + /* Start clean, so we can catch the change to REV polarity when party answers */ + p->polarity=POLARITY_IDLE; } } } @@ -4054,10 +4059,14 @@ /* If we get a ring then we cannot be in * reversed polarity. So we reset to idle */ - ast_log(LOG_DEBUG, "Setting IDLE polarity due " + /* This isn't working in Spain. We first + get a PR, then 1 or more RINGS. Setting + polarity to IDLE breaks remote hangup + detection */ + /*ast_log(LOG_DEBUG, "Setting IDLE polarity due " "to ring. Old polarity was %d\n", p->polarity); - p->polarity = POLARITY_IDLE; + p->polarity = POLARITY_IDLE;*/ /* Fall through */ case SIG_EM: @@ -6707,6 +6716,13 @@ case SIG_FXSLS: case SIG_FXSKS: case SIG_FXSGS: + /* We have already got a PR before the channel was + created, but it wasn't handled. We need polarity + to be REV for remote hangup detection to work. + At least in Spain */ + if (i->hanguponpolarityswitch) + i->polarity = POLARITY_REV; + if (i->cid_start == CID_START_POLARITY) { i->polarity = POLARITY_REV; ast_verbose(VERBOSE_PREFIX_2 "Starting post polarity "