Sim code refactoring

Refactoring of rilmodem sim code, plus fixes for LP 1225022, 1208657, and workaround for 1206941.