Device_state and Dahdi

I need for some reason to fetch the status of a dahdi channel in order to forward it to a panel.
I wanted to achieve this goal using device_state which seems to be there just for this purpose.
First attempt didn’t work for some reason so I googled looking for information and I got this Asterisk 0015227 issue, which seems fit perfectly in my situation.
It has however some exceptions.
In this issue it states that asterisk 1.6 is affected.
Actually I’m using version 1.8.8.1
it also suggest that “core show channeltype dahdi” should reveal that dahdi does not support device_state, but actually I got from this command:
– Info about channel driver: DAHDI –
Device State: yes
Indication: yes
Transfer : no
Capabilities: 0x4c (ulaw|alaw|slin)
Digit Begin: yes
Digit End: yes
Send HTML : no
Image Support: no
Text Support: yes
I’m confused.
Fact is that during the hangup performed on DAHDI/13 with dialplan such as
exten => h, 1, ChanIsAvail(DAHDI/13)
exten => h, n, NoOp(ISDN ext chan1: ${DEVICE_STATE(DAHDI/13)})
exten => h, n, NoOp(ISDN ext chan2: ${DEVICE_STATE(DAHDI/14)})
exten => h, n, NoOp(ISDN ext chan3: ${DEVICE_STATE(DAHDI/16)})
exten => h, n, NoOp(ISDN ext chan4: ${DEVICE_STATE(DAHDI/17)})
exten => h, n, noop(status: ${AVAILSTATUS} chan: ${AVAILCHAN})
exten => h, n, Set(DB(external/channel1)=FREE)
exten => h, n, Set(result=${SHELL(/etc/asterisk/mb_off.sh 01 &)})
exten => h, n, Hangup()
exten => h, 102, noop(nothing has to be done)
I got
– Executing [h@from-pstn_channel_1:1] ChanIsAvail(“DAHDI/i5/672679484-1”, “DAHDI/13”) in new stack
– Executing [h@from-pstn_channel_1:2] NoOp(“DAHDI/i5/672679484-1”, “ISDN ext chan1: UNKNOWN”) in new stack
– Executing [h@from-pstn_channel_1:3] NoOp(“DAHDI/i5/672679484-1”, “ISDN ext chan2: UNKNOWN”) in new stack
– Executing [h@from-pstn_channel_1:4] NoOp(“DAHDI/i5/672679484-1”, “ISDN ext chan3: UNKNOWN”) in new stack
– Executing [h@from-pstn_channel_1:5] NoOp(“DAHDI/i5/672679484-1”, “ISDN ext chan4: UNKNOWN”) in new stack
– Executing [h@from-pstn_channel_1:6] NoOp(“DAHDI/i5/672679484-1”, "status: 153191688 chan: ") in new stack
– Executing [h@from-pstn_channel_1:7] Set(“DAHDI/i5/672679484-1”, “DB(external/channel1)=FREE”) in new stack
– Executing [h@from-pstn_channel_1:8] Set(“DAHDI/i5/672679484-1”, “result=”) in new stack
– Executing [h@from-pstn_channel_1:9] Hangup(“DAHDI/i5/672679484-1”, “”) in new stack
== Spawn extension (from-pstn_channel_1, h, 9) exited non-zero on 'DAHDI/i5/672679484-1’
am I miss anything?
any suggestion would be appreciated.
Regards
AC

After a quite long session debugging I finally realized that dialplan function device_state can not be used as I intended.
I wanted to know, given a channel, its state.
For example at a given time I wanted to know channel 1 is used, channel 2 is free and so on.
Instead device_state on a dahdi channel, needs a parameter like “dahdi/I1/congestion or dahdi/I1/threshold”
"Congestion Congestion device state of the span.
Threshold An ISDN span threshold device state could be useful in determining how often a span utilization goes over a configurable threshold.
"
Where “I” is mandatory and indicates the port is an ISDN “span”, the number indicates the “span” and the final word indicates the function you want to know.

So device_state result is an information which says if that extension has been called on a given “span”.

So I still need a way to know the ISDN channel state on a given instant using a dialplan function.
Does anybody know a way to probe a given ISDN channel to know its state?
Any suggestion would be very apreciated.