Asterisk codec negotiation issue

I am experiencing some difficulties with Asterisk codec negotiation: The first leg sends the INVITE with AAL2-G726-32 which is included in the codec list in the INVITE sent from Asterisk to the second leg. The second leg (not supporting the codec) send OK with a codec list that does not contain AAL2-G726-32 to Asterisk. However, Asterisk sends OK to the first leg with AAL2-G726-32!

Untitled|553x421

I have attached an image that shows this. The call is made with one side sending g729 packets and the other sending AAL2-G726-32, hence no audio.

Is there any setting that I can modify to prevent Asterisk from negotiating a codec when one leg does not support it?

There is no feedback of the B side codecs. In any case, there may be multiple B sides with different codecs, or there may be voice announcement, or IVR, requiring an answer, before any B side is involved.

So, this is expected behaviour.