Index: channels/chan_sip.c =================================================================== --- channels/chan_sip.c (revision 47419) +++ channels/chan_sip.c (working copy) @@ -1308,7 +1308,6 @@ /*--- Device monitoring and Device/extension state handling */ static int cb_extensionstate(char *context, char* exten, int state, void *data); -static int sip_devicestate(void *data); static int sip_poke_noanswer(void *data); static int sip_poke_peer(struct sip_peer *peer); static void sip_poke_all_peers(void); @@ -8019,9 +8018,9 @@ /* If they put someone on hold, increment the value... otherwise decrement it */ if (hold) peer->onHold++; - else if (hold > 0) + else peer->onHold--; - + ast_log(LOG_NOTICE, "onHold now: %d; hold arg was: %d\n", peer->onHold, hold); /* Request device state update */ ast_device_state_changed("SIP/%s", peer->name); @@ -14885,18 +14884,16 @@ /* check call limit */ if (p->call_limit && (p->inUse == p->call_limit)) res = AST_DEVICE_BUSY; - else if (p->call_limit && p->inUse) + else if (p->onHold) + res = AST_DEVICE_ONHOLD; + else if (p->inRinging && p->inRinging == p->inUse) + res = AST_DEVICE_RINGING; + else if (p->inRinging) + res = AST_DEVICE_RINGINUSE; + else if (p->inUse) res = AST_DEVICE_INUSE; else res = AST_DEVICE_NOT_INUSE; - if (p->onHold) - res = AST_DEVICE_ONHOLD; - else if (p->inRinging) { - if (p->inRinging == p->inUse) - res = AST_DEVICE_RINGING; - else - res = AST_DEVICE_RINGINUSE; - } } } else { /* there is no address, it's unavailable */ @@ -14908,6 +14905,8 @@ if (hp) res = AST_DEVICE_UNKNOWN; } + ast_log(LOG_NOTICE, "sip_devicestate(%s) returning %s call-lim=%d, inuse=%d, onHold=%d, inRinging=%d\n", + host, devstate2str(res), p?p->call_limit:-101, p?p->inUse:-101, p?p->onHold:-101, p?p->inRinging:-101); return res; } Index: main/devicestate.c =================================================================== --- main/devicestate.c (revision 47419) +++ main/devicestate.c (working copy) @@ -117,11 +117,22 @@ if (!chan) return AST_DEVICE_UNKNOWN; + + switch (chan->_state) { - if (chan->_state == AST_STATE_RINGING) + case AST_STATE_RINGING: res = AST_DEVICE_RINGING; - else + break; + case AST_STATE_BUSY: + res = AST_DEVICE_BUSY; + break; + case AST_STATE_DOWN: + res = AST_DEVICE_NOT_INUSE; + break; + default: res = AST_DEVICE_INUSE; + break; + } ast_channel_unlock(chan);