aboutsummaryrefslogtreecommitdiffstats
path: root/host/simtrace2-remsim.c
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2017-05-11 01:12:50 +0200
committerHarald Welte <laforge@gnumonks.org>2017-05-11 01:13:04 +0200
commit66de830f5587831a8dfd7ef4afe339471e45801a (patch)
tree5fbdfad110e858618ef13e5838bac3bafc0d8a78 /host/simtrace2-remsim.c
parent23c00b6ad319fcbdaa3d82dbd47d356ae03df5d8 (diff)
host: Switch SIM to remote and issue modem reset on startup
as soon as simtrace2-remotesim is started, we issue the command to instruct the use of the remote SIM card and ask the modem to reset itself (to start using the new remote sim).
Diffstat (limited to 'host/simtrace2-remsim.c')
-rw-r--r--host/simtrace2-remsim.c75
1 files changed, 75 insertions, 0 deletions
diff --git a/host/simtrace2-remsim.c b/host/simtrace2-remsim.c
index f7cc666..8ac5a69 100644
--- a/host/simtrace2-remsim.c
+++ b/host/simtrace2-remsim.c
@@ -295,6 +295,72 @@ static int cardem_request_set_atr(struct cardem_inst *ci, const uint8_t *atr, un
}
/***********************************************************************
+ * Modem Control protocol
+ ***********************************************************************/
+
+static int _modem_reset(struct st_slot *slot, uint8_t asserted, uint16_t pulse_ms)
+{
+ struct msgb *msg = st_msgb_alloc();
+ struct st_modem_reset *sr ;
+
+ sr = (struct st_modem_reset *) msgb_put(msg, sizeof(*sr));
+ sr->asserted = asserted;
+ sr->pulse_duration_msec = pulse_ms;
+
+ return st_slot_tx_msg(slot, msg, SIMTRACE_MSGC_MODEM, SIMTRACE_MSGT_DT_MODEM_RESET);
+}
+
+/*! \brief pulse the RESET line of the modem for \a duration_ms milli-seconds*/
+int st_modem_reset_pulse(struct st_slot *slot, uint16_t duration_ms)
+{
+ return _modem_reset(slot, 2, duration_ms);
+}
+
+/*! \brief assert the RESET line of the modem */
+int st_modem_reset_active(struct st_slot *slot)
+{
+ return _modem_reset(slot, 1, 0);
+}
+
+/*! \brief de-assert the RESET line of the modem */
+int st_modem_reset_inactive(struct st_slot *slot)
+{
+ return _modem_reset(slot, 0, 0);
+}
+
+static int _modem_sim_select(struct st_slot *slot, uint8_t remote_sim)
+{
+ struct msgb *msg = st_msgb_alloc();
+ struct st_modem_sim_select *ss;
+
+ ss = (struct st_modem_sim_select *) msgb_put(msg, sizeof(*ss));
+ ss->remote_sim = remote_sim;
+
+ return st_slot_tx_msg(slot, msg, SIMTRACE_MSGC_MODEM, SIMTRACE_MSGT_DT_MODEM_SIM_SELECT);
+}
+
+/*! \brief select local (physical) SIM for given slot */
+int st_modem_sim_select_local(struct st_slot *slot)
+{
+ return _modem_sim_select(slot, 0);
+}
+
+/*! \brief select remote (emulated/forwarded) SIM for given slot */
+int st_modem_sim_select_remote(struct st_slot *slot)
+{
+ return _modem_sim_select(slot, 1);
+}
+
+/*! \brief Request slot to send us status information about the modem */
+int st_modem_get_status(struct st_slot *slot)
+{
+ struct msgb *msg = st_msgb_alloc();
+
+ return st_slot_tx_msg(slot, msg, SIMTRACE_MSGC_MODEM, SIMTRACE_MSGT_BD_MODEM_STATUS);
+}
+
+
+/***********************************************************************
* Incoming Messages
***********************************************************************/
@@ -666,13 +732,22 @@ int main(int argc, char **argv)
}
}
+ /* simulate card-insert to modem (owhw, not qmod) */
cardem_request_card_insert(ci, true);
+
+ /* select remote (forwarded) SIM */
+ st_modem_sim_select_remote(ci->slot);
+
+ /* set the ATR */
uint8_t real_atr[] = { 0x3B, 0x9F, 0x96, 0x80, 0x1F, 0xC7, 0x80, 0x31,
0xA0, 0x73, 0xBE, 0x21, 0x13, 0x67, 0x43, 0x20,
0x07, 0x18, 0x00, 0x00, 0x01, 0xA5 };
atr_update_csum(real_atr, sizeof(real_atr));
cardem_request_set_atr(ci, real_atr, sizeof(real_atr));
+ /* select remote (forwarded) SIM */
+ st_modem_reset_pulse(ci->slot, 300);
+
run_mainloop(ci);
ret = 0;