aboutsummaryrefslogtreecommitdiffstats
path: root/firmware/libcommon/source/card_emu.c
diff options
context:
space:
mode:
authorHarald Welte <laforge@osmocom.org>2019-12-14 22:20:00 +0100
committerHarald Welte <laforge@osmocom.org>2019-12-15 17:53:01 +0100
commit81f4ef77500cdbe862f5808373d375ae9ec8a853 (patch)
tree8408dfedcd4caccce26e57f58d06f02116feb854 /firmware/libcommon/source/card_emu.c
parentfa197ca3434b476f546a5237f2ea9285f8485927 (diff)
cardem: RST resets all state (including release of buffers)
When the Modem is asserting RST, the emulated card should set all of its state back to default/initial values and release any buffers it may still hold in its state. Change-Id: I66eca6afe4ff7d900c5b75df1e3ec6d52f6ef214 Related: OS#4251
Diffstat (limited to 'firmware/libcommon/source/card_emu.c')
-rw-r--r--firmware/libcommon/source/card_emu.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/firmware/libcommon/source/card_emu.c b/firmware/libcommon/source/card_emu.c
index 7ce10a8..63bf0d3 100644
--- a/firmware/libcommon/source/card_emu.c
+++ b/firmware/libcommon/source/card_emu.c
@@ -236,8 +236,25 @@ struct card_handle {
/* reset all the 'dynamic' state of the card handle to the initial/default values */
static void card_handle_reset(struct card_handle *ch)
{
+ struct msgb *msg;
+
+ tc_etu_disable(ch->tc_chan);
+
ch->pts.state = PTS_S_WAIT_REQ_PTSS;
ch->tpdu.state = TPDU_S_WAIT_CLA;
+
+ /* release any buffers we may still own */
+ if (ch->uart_tx_msg) {
+ usb_buf_free(ch->uart_tx_msg);
+ ch->uart_tx_msg = NULL;
+ }
+ if (ch->uart_rx_msg) {
+ usb_buf_free(ch->uart_rx_msg);
+ ch->uart_rx_msg = NULL;
+ }
+ while ((msg = msgb_dequeue(&ch->uart_tx_queue))) {
+ usb_buf_free(msg);
+ }
}
struct llist_head *card_emu_get_uart_tx_queue(struct card_handle *ch)
@@ -1062,7 +1079,7 @@ void card_emu_io_statechg(struct card_handle *ch, enum card_io io, int active)
case CARD_IO_VCC:
if (active == 0 && ch->vcc_active == 1) {
TRACE_INFO("%u: VCC deactivated\r\n", ch->num);
- tc_etu_disable(ch->tc_chan);
+ card_handle_reset(ch);
card_set_state(ch, ISO_S_WAIT_POWER);
} else if (active == 1 && ch->vcc_active == 0) {
TRACE_INFO("%u: VCC activated\r\n", ch->num);
@@ -1091,7 +1108,7 @@ void card_emu_io_statechg(struct card_handle *ch, enum card_io io, int active)
}
} else if (active && !ch->in_reset) {
TRACE_INFO("%u: RST asserted\r\n", ch->num);
- tc_etu_disable(ch->tc_chan);
+ card_handle_reset(ch);
}
ch->in_reset = active;
break;