How to differ "BUSY" and "DECLINED"

Colleagues, please tell me the answer to my question!
How to differ “BUSY” and “DECLINED”?

I’ll explain in a little more detail.
I am using a multi-channel SIP-GSM gateway. I access each channel from the dialplan.
If the my hardware is busy with another session, then it responds “DECLINED”. And this means you need to move on to the next one SIP-GSM channel.
If the hardware is available and sent a my call, then it returns other responds. This means that you can abort the connection establishment and exit the dialplan context.
Unfortunately, having received “DECLINED”, Asterisk generates dialstatus “BUSY”, which does not allow distinguishing between the two cases described above.

Is it possible to configure Asterisk so that upon receiving “DECLINED” it will return a different dialsatus, for example “CHANUNAVAIL”?

Thanks in advance for your reply,
Ogogon.

Do they create different simulated ISDN cause codes (HANGUPCAUSE). If so, use that. Otherwise, there are mechanisms to retrieve the raw SIP cause code.

Looking at some old code 486 returns AST_CAUSE_BUSY (17), 600 returns AST_CAUSE_USER_BUSY (also 17), 603 returns AST_CAUSE_CALL_REJECTED (21), etc. Look for sip2cause in the current source code for any changes.

Sounds like something the gateway (configured appropriately) should just handle.

Can you ask it to dial with a more generic name (like 'pjsip/${did}@goip')?