[Home]

Summary:ASTERISK-13532: app_chanisavail always set AVAILSTATUS to 0 with option 's' set
Reporter:Vincent Li (macli)Labels:
Date Opened:2009-02-06 13:34:17.000-0600Date Closed:2009-11-13 11:28:56.000-0600
Priority:MinorRegression?No
Status:Closed/CompleteComponents:Applications/app_chanisavail
Versions:Frequency of
Occurrence
Related
Issues:
Environment:Attachments:
Description:Here is dialplan copied from extensions.conf.sample:

[macro-page];

exten => s,1,ChanIsAvail(${ARG1},s)                     ; j is for Jump and s is for ANY call
exten => s,n,GoToIf($[ ${AVAILSTATUS} = 1 ]?autoanswer:fail)
exten => s,n(autoanswer),Set(_ALERT_INFO="RA")                  ; This is for the PolyComs
exten => s,n,SIPAddHeader(Call-Info: Answer-After=0)    ; This is for the Grandstream, Snoms, and Others
exten => s,n,NoOp()                                     ; Add others here and Post on the Wiki!!!!
exten => s,n,Dial(${ARG1},,)
exten => s,n(fail),Hangup

;page
exten => 6999,1,Set(TIMEOUT(absolute)=60)
exten => 6999,2,Macro(page,SIP/vli)



First call when SIP/vli not in use
----------------------------------

*CLI>     -- Starting simple switch on 'DAHDI/1-1'
   -- Executing [6999@brc-internal:1] Set("DAHDI/1-1", "TIMEOUT(absolute)=60") in new stack
Channel will hangup at 2009-02-06 11:49:08.454 PST.
   -- Executing [6999@brc-internal:2] Macro("DAHDI/1-1", "page,SIP/vli") in new stack
   -- Executing [s@macro-page:1] ChanIsAvail("DAHDI/1-1", "SIP/vli,s") in new stack
 == Using SIP RTP CoS mark 5
   -- Executing [s@macro-page:2] GotoIf("DAHDI/1-1", "0?autoanswer:fail") in new stack
 == branch1: autoanswer branch2: fail branch: fail
   -- Goto (macro-page,s,7)
   -- Executing [s@macro-page:7] Hangup("DAHDI/1-1", "") in new stack
 == Spawn extension (macro-page, s, 7) exited non-zero on 'DAHDI/1-1' in macro 'page'
 == Spawn extension (brc-internal, 6999, 2) exited non-zero on 'DAHDI/1-1'
   -- Hungup 'DAHDI/1-1'


Second call when SIP/vli is in use:
----------------------------------
*CLI> [Feb  6 11:49:16] NOTICE[12461]: chan_dahdi.c:7144 ss_thread: Got event 18 (Ring Begin)...
[Feb  6 11:49:19] NOTICE[12461]: chan_dahdi.c:7144 ss_thread: Got event 2 (Ring/Answered)...
   -- Executing [s@brc-incoming:1] Wait("DAHDI/4-1", "1") in new stack
   -- Executing [s@brc-incoming:2] Answer("DAHDI/4-1", "") in new stack
   -- Executing [s@brc-incoming:3] Playback("DAHDI/4-1", "brc/brc-office") in new stack
   -- <DAHDI/4-1> Playing 'brc/brc-office.gsm' (language 'en')
   -- Executing [s@brc-incoming:4] WaitExten("DAHDI/4-1", "5") in new stack
 == CDR updated on DAHDI/4-1
   -- Executing [668@brc-incoming:1] Gosub("DAHDI/4-1", "stdexten(668,SIP/vli)") in new stack
   -- Executing [668@brc-incoming:50000] NoOp("DAHDI/4-1", "Start stdexten") in new stack
   -- Executing [668@brc-incoming:50001] Set("DAHDI/4-1", "LOCAL(ext)=668") in new stack
   -- Executing [668@brc-incoming:50002] Set("DAHDI/4-1", "LOCAL(dev)=SIP/vli") in new stack
   -- Executing [668@brc-incoming:50003] Set("DAHDI/4-1", "LOCAL(cntx)=") in new stack
   -- Executing [668@brc-incoming:50004] Set("DAHDI/4-1", "LOCAL(mbx)="668"""") in new stack
   -- Executing [668@brc-incoming:50005] Dial("DAHDI/4-1", "SIP/vli,20,Tt") in new stack
 == Using SIP RTP CoS mark 5
   -- Called vli
   -- SIP/vli-083f31d8 is ringing
   -- SIP/vli-083f31d8 answered DAHDI/4-1

*CLI>     -- Starting simple switch on 'DAHDI/1-1'
   -- Executing [6999@brc-internal:1] Set("DAHDI/1-1", "TIMEOUT(absolute)=60") in new stack
Channel will hangup at 2009-02-06 11:50:48.558 PST.
   -- Executing [6999@brc-internal:2] Macro("DAHDI/1-1", "page,SIP/vli") in new stack
   -- Executing [s@macro-page:1] ChanIsAvail("DAHDI/1-1", "SIP/vli,s") in new stack
 == Using SIP RTP CoS mark 5
   -- Executing [s@macro-page:2] GotoIf("DAHDI/1-1", "0?autoanswer:fail") in new stack
 == branch1: autoanswer branch2: fail branch: fail
   -- Goto (macro-page,s,7)
   -- Executing [s@macro-page:7] Hangup("DAHDI/1-1", "") in new stack
 == Spawn extension (macro-page, s, 7) exited non-zero on 'DAHDI/1-1' in macro 'page'
 == Spawn extension (brc-internal, 6999, 2) exited non-zero on 'DAHDI/1-1'
   -- Hungup 'DAHDI/1-1'


****** ADDITIONAL INFORMATION ******

I tested on asterisk-1.4.23.1 and asterisk-1.6.1-rc1, they both have this same problem
Comments:By: Vincent Li (macli) 2009-02-06 18:11:26.000-0600

The following one line change patch would fix the problem.

--- asterisk-1.6.1-rc1.orig/apps/app_chanisavail.c      2008-06-12 10:27:55.000000000 -0700
+++ asterisk-1.6.1-rc1/apps/app_chanisavail.c   2009-02-06 16:35:10.000000000 -0800
@@ -127,7 +127,7 @@
                               snprintf(trychan, sizeof(trychan), "%s/%s",cur,number);
                               status = inuse = ast_device_state(trychan);
                       }
-                       if ((inuse <= 1) && (tempchan = ast_request(tech, chan->nativeformats, number, &status))) {
+                       if ((inuse > 1) && (tempchan = ast_request(tech, chan->nativeformats, number, &status))) {
                                       ast_str_append(&tmp_availchan, 0, "%s%s", tmp_availchan->used ? "&" : "", tempchan->name);

                                       snprintf(tmp, sizeof(tmp), "%s/%s", tech, number);



By: snuffy (snuffy) 2009-02-07 04:39:10.000-0600

macli.. we cannot accept even a 1 line patch without you uploading it via the method provided. (which requires you to sign the license agreement)

By: Mark Michelson (mmichelson) 2009-02-07 12:51:31.000-0600

macli, that patch is not a good idea.

The problem appears to be that AVAILSTATUS is being used for two distinct purposes here. In the case where inuse <= 1, the status gets overriden in the ast_request call with a Q.931 cause code describing the reason the channel could or could not be requested. In the case where inuse > 1, the status corresponds to the device state of the channel.

Unfortunately, it's very hard to judge the intent of the ChanIsAvail application just from reading the code and its CLI documentation. As a result of potential ambiguities, I have several ideas for patches that would fix this problem.

As a workaround for now, you can use the AVAILORIGCHAN variable as a means of determining if the channel is available. In macro-page, change the second line to be

exten => s,n,GoToIf(${EXISTS(${AVAILORIGCHAN})}?autoanswer:fail)

By: Vincent Li (macli) 2009-02-09 15:40:30.000-0600

inuse <= 1 translate to either AST_DEVICE_UNKNOWN or AST_DEVICE_NOT_INUSE  

AST_DEVICE_UNKNOWN,      /*!< Device is valid but channel didn't know state */
AST_DEVICE_NOT_INUSE,    /*!< Device is not used */

if ((inuse <= 1) && (tempchan = ast_request(tech, chan->nativeformats, number, &status)))

If the device is not in use, how would ast_request get tempchan for the device? so the above conditions seems contradicting to me.

By: Mark Michelson (mmichelson) 2009-02-09 16:03:13.000-0600

The problem is that you are misinterpreting what ast_request does. ast_request is a wrapper function which causes a channel driver to create a new channel. If the channel we are requesting is currently in use, ringing, busy, or any of the other states > 1, then we know that the channel driver will refuse our request. This is why we only attempt to request a new channel if the device state is currently unknown or not in use.

By: Mark Michelson (mmichelson) 2009-02-09 16:03:53.000-0600

I'm changing the status of this to "acknowledged" since no feedback is required right now.

By: Digium Subversion (svnbot) 2009-11-13 11:26:07.000-0600

Repository: asterisk
Revision: 229965

U   branches/1.4/apps/app_chanisavail.c
U   branches/1.4/configs/extensions.conf.sample

------------------------------------------------------------------------
r229965 | file | 2009-11-13 11:26:07 -0600 (Fri, 13 Nov 2009) | 6 lines

Document a limitation in the AVAILSTATUS variable from ChanIsAvail and provide
a workaround for it that does not change existing behavior.

(closes issue ASTERISK-13532)
Reported by: macli

------------------------------------------------------------------------

http://svn.digium.com/view/asterisk?view=rev&revision=229965

By: Digium Subversion (svnbot) 2009-11-13 11:26:35.000-0600

Repository: asterisk
Revision: 229966

_U  trunk/

------------------------------------------------------------------------
r229966 | file | 2009-11-13 11:26:34 -0600 (Fri, 13 Nov 2009) | 13 lines

Merged revisions 229965 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4

........
 r229965 | file | 2009-11-13 11:19:59 -0600 (Fri, 13 Nov 2009) | 6 lines
 
 Document a limitation in the AVAILSTATUS variable from ChanIsAvail and provide
 a workaround for it that does not change existing behavior.
 
 (closes issue ASTERISK-13532)
 Reported by: macli
........

------------------------------------------------------------------------

http://svn.digium.com/view/asterisk?view=rev&revision=229966

By: Digium Subversion (svnbot) 2009-11-13 11:27:01.000-0600

Repository: asterisk
Revision: 229967

_U  branches/1.6.0/
U   branches/1.6.0/apps/app_chanisavail.c
U   branches/1.6.0/configs/extensions.conf.sample

------------------------------------------------------------------------
r229967 | file | 2009-11-13 11:27:01 -0600 (Fri, 13 Nov 2009) | 20 lines

Merged revisions 229966 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk

................
 r229966 | file | 2009-11-13 11:20:26 -0600 (Fri, 13 Nov 2009) | 13 lines
 
 Merged revisions 229965 via svnmerge from
 https://origsvn.digium.com/svn/asterisk/branches/1.4
 
 ........
   r229965 | file | 2009-11-13 11:19:59 -0600 (Fri, 13 Nov 2009) | 6 lines
   
   Document a limitation in the AVAILSTATUS variable from ChanIsAvail and provide
   a workaround for it that does not change existing behavior.
   
   (closes issue ASTERISK-13532)
   Reported by: macli
 ........
................

------------------------------------------------------------------------

http://svn.digium.com/view/asterisk?view=rev&revision=229967

By: Digium Subversion (svnbot) 2009-11-13 11:27:34.000-0600

Repository: asterisk
Revision: 229968

_U  branches/1.6.1/
U   branches/1.6.1/apps/app_chanisavail.c
U   branches/1.6.1/configs/extensions.conf.sample

------------------------------------------------------------------------
r229968 | file | 2009-11-13 11:27:34 -0600 (Fri, 13 Nov 2009) | 20 lines

Merged revisions 229966 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk

................
 r229966 | file | 2009-11-13 11:20:26 -0600 (Fri, 13 Nov 2009) | 13 lines
 
 Merged revisions 229965 via svnmerge from
 https://origsvn.digium.com/svn/asterisk/branches/1.4
 
 ........
   r229965 | file | 2009-11-13 11:19:59 -0600 (Fri, 13 Nov 2009) | 6 lines
   
   Document a limitation in the AVAILSTATUS variable from ChanIsAvail and provide
   a workaround for it that does not change existing behavior.
   
   (closes issue ASTERISK-13532)
   Reported by: macli
 ........
................

------------------------------------------------------------------------

http://svn.digium.com/view/asterisk?view=rev&revision=229968

By: Digium Subversion (svnbot) 2009-11-13 11:27:57.000-0600

Repository: asterisk
Revision: 229969

_U  branches/1.6.2/
U   branches/1.6.2/apps/app_chanisavail.c
U   branches/1.6.2/configs/extensions.conf.sample

------------------------------------------------------------------------
r229969 | file | 2009-11-13 11:27:57 -0600 (Fri, 13 Nov 2009) | 20 lines

Merged revisions 229966 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk

................
 r229966 | file | 2009-11-13 11:20:26 -0600 (Fri, 13 Nov 2009) | 13 lines
 
 Merged revisions 229965 via svnmerge from
 https://origsvn.digium.com/svn/asterisk/branches/1.4
 
 ........
   r229965 | file | 2009-11-13 11:19:59 -0600 (Fri, 13 Nov 2009) | 6 lines
   
   Document a limitation in the AVAILSTATUS variable from ChanIsAvail and provide
   a workaround for it that does not change existing behavior.
   
   (closes issue ASTERISK-13532)
   Reported by: macli
 ........
................

------------------------------------------------------------------------

http://svn.digium.com/view/asterisk?view=rev&revision=229969

By: Digium Subversion (svnbot) 2009-11-13 11:28:55.000-0600

Repository: asterisk
Revision: 229970

U   trunk/CHANGES
U   trunk/UPGRADE.txt
U   trunk/apps/app_chanisavail.c

------------------------------------------------------------------------
r229970 | file | 2009-11-13 11:28:55 -0600 (Fri, 13 Nov 2009) | 6 lines

Store the cause code that is returned when trying to create a channel in ChanIsAvail in the
AVAILCAUSECODE dialplan variable instead of overwriting the device state in AVAILSTATUS.

(closes issue ASTERISK-13532)
Reported by: macli

------------------------------------------------------------------------

http://svn.digium.com/view/asterisk?view=rev&revision=229970