iap: introduce cmd_ok_mode0 and cmd_ok_mode4 functions to reduce code duplication