fsm completion event handling from main loop

The main loop will now poll for finished/failed transactions and handle
them, this was previously handled during the last rx interrupt of a
transaction, which was bad for timing. This does also fix malloc/free
while handling interrupts.

Change-Id: I055110720089e20e65db592eccc3ce4d618e8c63
diff --git a/ccid_common/iso7816_fsm.c b/ccid_common/iso7816_fsm.c
index 3778dcc..44c8191 100644
--- a/ccid_common/iso7816_fsm.c
+++ b/ccid_common/iso7816_fsm.c
@@ -238,6 +238,8 @@
 		osmo_fsm_inst_state_chg_ms(fi, ISO7816_S_WAIT_ATR,
 					   fi_cycles2ms(fi, 40000), T_WAIT_ATR);
 		break;
+	case ISO7816_E_POWER_UP_IND:
+		break;
 	case ISO7816_E_PPS_FAILED_IND:
 		msg = data;
 		/* notify user about PPS result */
@@ -876,7 +878,7 @@
 		msgb_reset(atp->rx_cmd);
 
 	/* notify in case card got pulled out */
-	if (atp->tx_cmd){
+	if (atp->tx_cmd && old_state != PPS_S_DONE){
 		osmo_fsm_inst_dispatch(fi->proc.parent,
 				ISO7816_E_PPS_FAILED_IND, atp->tx_cmd);
 		atp->tx_cmd = 0;
@@ -1099,7 +1101,7 @@
 	struct tpdu_fsm_priv *tfp = get_tpdu_fsm_priv(fi);
 
 	/* notify in case card got pulled out */
-	if (tfp->tpdu){
+	if (tfp->tpdu && old_state != TPDU_S_DONE){
 		osmo_fsm_inst_dispatch(fi->proc.parent, ISO7816_E_TPDU_FAILED_IND, tfp->tpdu);
 		tfp->tpdu = 0;
 	}