Electronic structure and magnetic interactions in Mn doped semiconductors