Index: channels/chan_zap.c =================================================================== --- channels/chan_zap.c (revision 62036) +++ channels/chan_zap.c (working copy) @@ -4054,10 +4054,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 +6711,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 "