card_uart_tx: Allow caller to specify if Rx should be active after Tx
This reverts commit 02dd9111635a8adbcd804671695de88f22ffa5ae.
Change-Id: Ibe02d283701dbfff5ab47e1b8195369c134cde03
diff --git a/ccid_common/cuart.c b/ccid_common/cuart.c
index 4ea82ba..9a68167 100644
--- a/ccid_common/cuart.c
+++ b/ccid_common/cuart.c
@@ -112,7 +112,7 @@
return rc;
}
-int card_uart_tx(struct card_uart *cuart, const uint8_t *data, size_t len)
+int card_uart_tx(struct card_uart *cuart, const uint8_t *data, size_t len, bool rx_after_complete)
{
OSMO_ASSERT(cuart);
OSMO_ASSERT(cuart->driver);
@@ -121,6 +121,7 @@
OSMO_ASSERT(!cuart->tx_busy);
cuart->tx_busy = true;
+ cuart->rx_after_tx_compl = rx_after_complete;
/* disable receiver to avoid receiving what we transmit */
card_uart_ctrl(cuart, CUART_CTL_RX, false);
@@ -150,7 +151,8 @@
case CUART_E_TX_COMPLETE:
cuart->tx_busy = false;
/* re-enable receiver if we're done with transmit */
- card_uart_ctrl(cuart, CUART_CTL_RX, true);
+ if (cuart->rx_after_tx_compl)
+ card_uart_ctrl(cuart, CUART_CTL_RX, true);
break;
default:
break;
diff --git a/ccid_common/cuart.h b/ccid_common/cuart.h
index 9d56035..b94eb2c 100644
--- a/ccid_common/cuart.h
+++ b/ccid_common/cuart.h
@@ -62,6 +62,8 @@
bool tx_busy;
/* is the receiver currently enabled or not? */
bool rx_enabled;
+ /* should the receiver automatically be nabled after TX completion? */
+ bool rx_after_tx_compl;
/*! after how many bytes should we notify the user? If this is '1', we will
* issue CUART_E_RX_SINGLE; if it is > 1, we will issue CUART_E_RX_COMPLETE */
@@ -98,7 +100,7 @@
int card_uart_close(struct card_uart *cuart);
/*! Schedule (asynchronous) transmit data via UART; optionally enable Rx after completion */
-int card_uart_tx(struct card_uart *cuart, const uint8_t *data, size_t len);
+int card_uart_tx(struct card_uart *cuart, const uint8_t *data, size_t len, bool rx_after_complete);
/*! Schedule (asynchronous) receive data via UART (after CUART_E_RX_COMPLETE) */
int card_uart_rx(struct card_uart *cuart, uint8_t *data, size_t len);
diff --git a/ccid_common/iso7816_fsm.c b/ccid_common/iso7816_fsm.c
index e173030..b98e2bb 100644
--- a/ccid_common/iso7816_fsm.c
+++ b/ccid_common/iso7816_fsm.c
@@ -829,7 +829,7 @@
tfp->is_command ? "COMMAND" : "RESPONSE",
osmo_hexdump_nospc((uint8_t *) tpduh, sizeof(*tpduh)));
osmo_fsm_inst_state_chg(fi, TPDU_S_TX_HDR, 0, 0);
- card_uart_tx(ip->uart, (uint8_t *) tpduh, sizeof(*tpduh));
+ card_uart_tx(ip->uart, (uint8_t *) tpduh, sizeof(*tpduh), true);
break;
default:
OSMO_ASSERT(0);
@@ -875,7 +875,7 @@
} else if (byte == tpduh->ins) {
if (tfp->is_command) {
/* transmit all remaining bytes */
- card_uart_tx(ip->uart, msgb_l2(tfp->tpdu), msgb_l2len(tfp->tpdu));
+ card_uart_tx(ip->uart, msgb_l2(tfp->tpdu), msgb_l2len(tfp->tpdu), true);
osmo_fsm_inst_state_chg(fi, TPDU_S_TX_REMAINING, 0, 0);
} else {
card_uart_set_rx_threshold(ip->uart, tpduh->p3);
@@ -886,7 +886,7 @@
if (tfp->is_command) {
/* transmit *next*, not first byte */
OSMO_ASSERT(msgb_l3len(tfp->tpdu) >= 0);
- card_uart_tx(ip->uart, msgb_l3(tfp->tpdu), 1);
+ card_uart_tx(ip->uart, msgb_l3(tfp->tpdu), 1, false);
osmo_fsm_inst_state_chg(fi, TPDU_S_TX_SINGLE, 0, 0);
} else {
osmo_fsm_inst_state_chg(fi, TPDU_S_RX_SINGLE, 0, 0);
diff --git a/ccid_host/cuart_test.c b/ccid_host/cuart_test.c
index d4d8faf..0ed6614 100644
--- a/ccid_host/cuart_test.c
+++ b/ccid_host/cuart_test.c
@@ -44,7 +44,7 @@
static void test_apdu(void)
{
const uint8_t select_mf[] = "\xa0\xa4\x04\x00\x02\x3f\x00";
- card_uart_tx(&g_cuart, select_mf, 5);
+ card_uart_tx(&g_cuart, select_mf, 5, true);
osmo_select_main(true);
sleep(1);