From c79b58200025a1371e56845d8084defe8561c048 Mon Sep 17 00:00:00 2001 From: Alexander Couzens Date: Fri, 31 May 2024 16:43:03 +0200 Subject: [PATCH] simtrace2-cardem-pcsc: allow to set sim presence polarity Add api call osmo_st2_cardem_request_config2(struct cardemu_usb_msg_config *) which contains a full cardemu_usb_msg_config. Change-Id: Iacde63e667472a85a5f18cb4ca99dcfa1a84dd59 --- TODO-RELEASE | 1 + host/include/osmocom/simtrace2/simtrace2_api.h | 4 +++- host/lib/simtrace2_api.c | 15 +++++++++++++++ host/src/simtrace2-cardem-pcsc.c | 11 +++++++++-- 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/TODO-RELEASE b/TODO-RELEASE index fb357238..3b33942f 100644 --- a/TODO-RELEASE +++ b/TODO-RELEASE @@ -9,3 +9,4 @@ #library what description / commit summary line simtrace2 API/ABI change osmo_st2_transport new member simtrace2 API/ABI change cardemu_usb_msg_config new member +simtrace2 API/ABI change add function osmo_st2_cardem_request_config2() diff --git a/host/include/osmocom/simtrace2/simtrace2_api.h b/host/include/osmocom/simtrace2/simtrace2_api.h index d658d161..a29389c8 100644 --- a/host/include/osmocom/simtrace2/simtrace2_api.h +++ b/host/include/osmocom/simtrace2/simtrace2_api.h @@ -41,6 +41,8 @@ struct osmo_st2_cardem_inst { void *priv; }; +struct cardemu_usb_msg_config; + int osmo_st2_slot_tx_msg(struct osmo_st2_slot *slot, struct msgb *msg, uint8_t msg_class, uint8_t msg_type); @@ -53,7 +55,7 @@ int osmo_st2_cardem_request_sw_tx(struct osmo_st2_cardem_inst *ci, const uint8_t int osmo_st2_cardem_request_set_atr(struct osmo_st2_cardem_inst *ci, const uint8_t *atr, unsigned int atr_len); int osmo_st2_cardem_request_config(struct osmo_st2_cardem_inst *ci, uint32_t features); - +int osmo_st2_cardem_request_config2(struct osmo_st2_cardem_inst *ci, const struct cardemu_usb_msg_config *config); int osmo_st2_modem_reset_pulse(struct osmo_st2_slot *slot, uint16_t duration_ms); int osmo_st2_modem_reset_active(struct osmo_st2_slot *slot); diff --git a/host/lib/simtrace2_api.c b/host/lib/simtrace2_api.c index 4ad7eb75..37be08af 100644 --- a/host/lib/simtrace2_api.c +++ b/host/lib/simtrace2_api.c @@ -272,6 +272,21 @@ int osmo_st2_cardem_request_config(struct osmo_st2_cardem_inst *ci, uint32_t fea return osmo_st2_slot_tx_msg(ci->slot, msg, SIMTRACE_MSGC_CARDEM, SIMTRACE_MSGT_BD_CEMU_CONFIG); } +/* user_cfg is in host byte order. */ +int osmo_st2_cardem_request_config2(struct osmo_st2_cardem_inst *ci, const struct cardemu_usb_msg_config *user_cfg) +{ + struct msgb *msg = st_msgb_alloc(); + struct cardemu_usb_msg_config *tx_cfg; + + tx_cfg = (struct cardemu_usb_msg_config *) msgb_put(msg, sizeof(*tx_cfg)); + + LOGSLOT(ci->slot, LOGL_NOTICE, "<= %s(features=%08x)\n", __func__, tx_cfg->features); + memcpy(tx_cfg, user_cfg, sizeof(*tx_cfg)); + osmo_store32le(user_cfg->features, &tx_cfg->features); + + return osmo_st2_slot_tx_msg(ci->slot, msg, SIMTRACE_MSGC_CARDEM, SIMTRACE_MSGT_BD_CEMU_CONFIG); +} + /*********************************************************************** * Modem Control protocol ***********************************************************************/ diff --git a/host/src/simtrace2-cardem-pcsc.c b/host/src/simtrace2-cardem-pcsc.c index 4acf268d..f26698e8 100644 --- a/host/src/simtrace2-cardem-pcsc.c +++ b/host/src/simtrace2-cardem-pcsc.c @@ -413,6 +413,7 @@ static void print_help(void) "\t-S\t--usb-altsetting ALTSETTING_ID\n" "\t-A\t--usb-address\tADDRESS\n" "\t-H\t--usb-path\tPATH\n" + "\t-Z\t--set-sim-presence\t<0/1>\n" "\n" ); } @@ -431,6 +432,7 @@ static const struct option opts[] = { { "usb-altsetting", 1, 0, 'S' }, { "usb-address", 1, 0, 'A' }, { "usb-path", 1, 0, 'H' }, + { "set-sim-presence", 1, 0, 'Z' }, { NULL, 0, 0, 0 } }; @@ -487,6 +489,7 @@ int main(int argc, char **argv) char *path = NULL; struct osim_reader_hdl *reader; struct osim_card_hdl *card; + struct cardemu_usb_msg_config cardem_config = { .features = CEMU_FEAT_F_STATUS_IRQ }; print_welcome(); @@ -509,7 +512,7 @@ int main(int argc, char **argv) while (1) { int option_index = 0; - c = getopt_long(argc, argv, "hi:V:P:C:I:S:A:H:akn:t:", opts, &option_index); + c = getopt_long(argc, argv, "hi:V:P:C:I:S:A:H:akn:t:Z:", opts, &option_index); if (c == -1) break; switch (c) { @@ -553,6 +556,10 @@ int main(int argc, char **argv) case 'H': path = optarg; break; + case 'Z': + cardem_config.pres_pol = atoi(optarg) ? CEMU_CONFIG_PRES_POL_PRES_H : 0; + cardem_config.pres_pol |= CEMU_CONFIG_PRES_POL_VALID; + break; } } @@ -636,7 +643,7 @@ int main(int argc, char **argv) allocate_and_submit_in(ci); /* request firmware to generate STATUS on IRQ endpoint */ - osmo_st2_cardem_request_config(ci, CEMU_FEAT_F_STATUS_IRQ); + osmo_st2_cardem_request_config2(ci, &cardem_config); /* simulate card-insert to modem (owhw, not qmod) */ osmo_st2_cardem_request_card_insert(ci, true);