laforge has submitted this change. (
https://gerrit.osmocom.org/c/simtrace2/+/36981?usp=email )
Change subject: firmware: allow to change the sim presence pin polarity
......................................................................
firmware: allow to change the sim presence pin polarity
The sim presence pin allows the simtrace2 to inform the modem
about the presence of the simcard. On a generic simcard slot a
button is pressed by the simcard which generate a high or low voltage level.
Even though there are specifications of minipcie or ngff defining this signal, certain
modems behave different.
Certain modems require different signals from the specification.
Extend the usb protocol to set the behaviour at runtime.
Related: SYS#6946
Change-Id: I77118114ba873fdf0778137402888b40f2442456
---
M TODO-RELEASE
M firmware/libcommon/include/simtrace.h
M firmware/libcommon/include/simtrace_prot.h
M firmware/libcommon/source/card_emu.c
M firmware/libcommon/source/mode_cardemu.c
M firmware/test/Makefile
M firmware/test/card_emu_tests.c
7 files changed, 83 insertions(+), 5 deletions(-)
Approvals:
Jenkins Builder: Verified
laforge: Looks good to me, approved
diff --git a/TODO-RELEASE b/TODO-RELEASE
index 5da461b..fb35723 100644
--- a/TODO-RELEASE
+++ b/TODO-RELEASE
@@ -8,3 +8,4 @@
# If any interfaces have been removed or changed since the last public release: c:r:0.
#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
diff --git a/firmware/libcommon/include/simtrace.h
b/firmware/libcommon/include/simtrace.h
index a37ec4f..4a7aca1 100644
--- a/firmware/libcommon/include/simtrace.h
+++ b/firmware/libcommon/include/simtrace.h
@@ -124,4 +124,8 @@
void Timer_Init( void );
void TC0_Counter_Reset( void );
+/* Sim presence pins */
+bool mode_cardemu_get_presence_pol(uint8_t instance);
+void mode_cardemu_set_presence_pol(uint8_t instance, bool high);
+
#endif /* SIMTRACE_H */
diff --git a/firmware/libcommon/include/simtrace_prot.h
b/firmware/libcommon/include/simtrace_prot.h
index d1eb89b..50042a0 100644
--- a/firmware/libcommon/include/simtrace_prot.h
+++ b/firmware/libcommon/include/simtrace_prot.h
@@ -261,12 +261,21 @@
/* enable/disable the generation of DO_STATUS on IRQ endpoint */
#define CEMU_FEAT_F_STATUS_IRQ 0x00000001
+#define CEMU_CONFIG_PRES_POL_PRES_L 0x00
+#define CEMU_CONFIG_PRES_POL_PRES_H 0x01
+#define CEMU_CONFIG_PRES_POL_VALID 0x02
+
/* SIMTRACE_MSGT_BD_CEMU_CONFIG */
struct cardemu_usb_msg_config {
/* bit-mask of CEMU_FEAT_F flags */
uint32_t features;
/* the selected slot number (if an external mux is present) */
uint8_t slot_mux_nr;
+ /* Sim presence pin polarity. Bit 1 is a validity bit. Bit 0 gpio value when sim
present.
+ * When sim is present, set sim_present gpio to high -> 0x03
+ * When sim is present, set sim_present gpio to low -> 0x02
+ */
+ uint8_t pres_pol;
} __attribute__ ((packed));
/***********************************************************************
diff --git a/firmware/libcommon/source/card_emu.c b/firmware/libcommon/source/card_emu.c
index e6907e6..ab54fc5 100644
--- a/firmware/libcommon/source/card_emu.c
+++ b/firmware/libcommon/source/card_emu.c
@@ -24,6 +24,7 @@
#include "trace.h"
#include "iso7816_fidi.h"
#include "card_emu.h"
+#include "simtrace.h"
#include "simtrace_prot.h"
#include "usb_buf.h"
#include <osmocom/core/linuxlist.h>
@@ -1096,7 +1097,7 @@
#else
cfg->slot_mux_nr = 0;
#endif
-
+ cfg->pres_pol = mode_cardemu_get_presence_pol(ch->num) |
CEMU_CONFIG_PRES_POL_VALID;
usb_buf_upd_len_and_submit(msg);
}
@@ -1270,6 +1271,11 @@
}
#endif
+ if (scfg_len >= sizeof(uint32_t)+sizeof(uint8_t)+sizeof(uint8_t)) {
+ if (scfg->pres_pol & CEMU_CONFIG_PRES_POL_VALID)
+ mode_cardemu_set_presence_pol(ch->num, scfg->pres_pol &
CEMU_CONFIG_PRES_POL_PRES_H);
+ }
+
/* send back a report of our current configuration */
card_emu_report_config(ch);
diff --git a/firmware/libcommon/source/mode_cardemu.c
b/firmware/libcommon/source/mode_cardemu.c
index a05840e..a5485e4 100644
--- a/firmware/libcommon/source/mode_cardemu.c
+++ b/firmware/libcommon/source/mode_cardemu.c
@@ -79,7 +79,10 @@
uint8_t ep_out;
uint8_t ep_in;
uint8_t ep_int;
+ /*! Pin to set when SIM is present/inserted (SIM presence pin). */
const Pin pin_insert;
+ /*! Invert the Pin polarity. When not inverted, the SIM pin_insert will be High, when a
SIM is present. */
+ bool pin_insert_inverted;
#ifdef DETECT_VCC_BY_ADC
uint32_t vcc_uv;
#endif
@@ -113,7 +116,10 @@
.ep_int = SIMTRACE_CARDEM_USB_EP_USIM1_INT,
#ifdef PIN_SET_USIM1_PRES
.pin_insert = PIN_SET_USIM1_PRES,
-#endif
+#endif /* PIN_SET_USIM1_PRES */
+#ifdef PIN_SET_USIM1_PRES_INVERTED
+ .pin_insert_inverted = true,
+#endif /* PIN_SET_USIM1_PRES_INVERTED */
},
#ifdef CARDEMU_SECOND_UART
{
@@ -128,7 +134,10 @@
.ep_int = SIMTRACE_CARDEM_USB_EP_USIM2_INT,
#ifdef PIN_SET_USIM2_PRES
.pin_insert = PIN_SET_USIM2_PRES,
-#endif
+#endif /* PIN_SET_USIM2_PRES */
+#ifdef PIN_SET_USIM2_PRES_INVERTED
+ .pin_insert_inverted = true,
+#endif /* PIN_SET_USIM2_PRES_INVERTED */
},
#endif
};
@@ -700,7 +709,7 @@
TRACE_INFO("%u: set card_insert to %s\r\n", ci->num, card_insert ?
"INSERTED" : "REMOVED");
#ifdef HAVE_BOARD_CARDINSERT
- board_set_card_insert(ci, card_insert);
+ board_set_card_insert(ci, card_insert ^ ci->pin_insert_inverted);
#else
if (!ci->pin_insert.pio) {
TRACE_INFO("%u: skipping unsupported card_insert to %s\r\n",
@@ -708,7 +717,7 @@
return;
}
- if (card_insert)
+ if (card_insert ^ ci->pin_insert_inverted)
PIO_Set(&ci->pin_insert);
else
PIO_Clear(&ci->pin_insert);
@@ -962,3 +971,25 @@
process_any_usb_commands(queue, ci);
}
}
+
+void mode_cardemu_set_presence_pol(uint8_t instance, bool high)
+{
+ struct cardem_inst *ci;
+
+ if (instance >= ARRAY_SIZE(cardem_inst))
+ return;
+
+ ci = &cardem_inst[instance];
+ ci->pin_insert_inverted = !high;
+}
+
+bool mode_cardemu_get_presence_pol(uint8_t instance)
+{
+ struct cardem_inst *ci;
+
+ if (instance >= ARRAY_SIZE(cardem_inst))
+ return false;
+
+ ci = &cardem_inst[instance];
+ return !ci->pin_insert_inverted;
+}
diff --git a/firmware/test/Makefile b/firmware/test/Makefile
index 4341c92..883219b 100644
--- a/firmware/test/Makefile
+++ b/firmware/test/Makefile
@@ -7,6 +7,7 @@
-I../atmel_softpack_libraries/libchip_sam3s/cmsis \
-I../atmel_softpack_libraries/libchip_sam3s/include \
-I../atmel_softpack_libraries/usb/include \
+ -I../atmel_softpack_libraries/ \
-I../libcommon/include \
-I../libboard/common/include \
-I../libboard/simtrace/include \
diff --git a/firmware/test/card_emu_tests.c b/firmware/test/card_emu_tests.c
index 5d5bd3e..1fa4a88 100644
--- a/firmware/test/card_emu_tests.c
+++ b/firmware/test/card_emu_tests.c
@@ -93,7 +93,14 @@
printf("%s(uart_chan=%u\n", __func__, uart_chan);
}
+void mode_cardemu_set_presence_pol(uint8_t instance, bool high)
+{
+}
+bool mode_cardemu_get_presence_pol(uint8_t instance)
+{
+ return false;
+}
/***********************************************************************
* test helper functions
--
To view, visit
https://gerrit.osmocom.org/c/simtrace2/+/36981?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings
Gerrit-Project: simtrace2
Gerrit-Branch: master
Gerrit-Change-Id: I77118114ba873fdf0778137402888b40f2442456
Gerrit-Change-Number: 36981
Gerrit-PatchSet: 7
Gerrit-Owner: lynxis lazus <lynxis(a)fe80.eu>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: neels <nhofmeyr(a)sysmocom.de>
Gerrit-MessageType: merged