SIP trunk registration indication to other module

Hi,

I have a home gateway on this, I am running asterisk1.8. The HG has an FXS port to which my telephone is connected.

Scenario:
Asterisk registers itself as a trunk to a VOIP provider. When it fails, I would like the telephone to give me a busy dialtone.

Problem:
How can I check when trunk registration fails in another module. Dialplan is only executed when all the numbers are dialled from my telephone and then from Dialplan I can check whether the state of the channel is unavailable or not.

I can hack in to the code as well but I would like to have a decent solution. Maybe I am missing something.

Greetings,
m

Try using the DEVICE_STATE() function.