mirror of
https://gitea.osmocom.org/sim-card/simtrace2.git
synced 2026-03-18 06:08:31 +03:00
Compare commits
22 Commits
laforge/ca
...
laforge/ca
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
87c5bdf329 | ||
|
|
76c73aaa99 | ||
|
|
e33c2907bc | ||
|
|
0f75d6ef1e | ||
|
|
c690a1f130 | ||
|
|
8e6ba005d4 | ||
|
|
206d613b4d | ||
|
|
7b681981ea | ||
|
|
e410842d8e | ||
|
|
752bc7f4b5 | ||
|
|
7f421ef014 | ||
|
|
a708ea1d99 | ||
|
|
c1ffc8a603 | ||
|
|
79f0ea73a2 | ||
|
|
9454a062b5 | ||
|
|
6b7f8d142f | ||
|
|
9c95162d5c | ||
|
|
878fadd74f | ||
|
|
9e0e0ddd5a | ||
|
|
7a3d93682f | ||
|
|
01868775ba | ||
|
|
9ec3de9346 |
@@ -28,7 +28,7 @@ export PKG_CONFIG_PATH="$inst/lib/pkgconfig:$PKG_CONFIG_PATH"
|
|||||||
export LD_LIBRARY_PATH="$inst/lib"
|
export LD_LIBRARY_PATH="$inst/lib"
|
||||||
|
|
||||||
BUILDS=""
|
BUILDS=""
|
||||||
BUILDS+="simtrace/dfu simtrace/trace "
|
BUILDS+="simtrace/dfu simtrace/trace simtrace/cardem "
|
||||||
BUILDS+="qmod/dfu qmod/cardem "
|
BUILDS+="qmod/dfu qmod/cardem "
|
||||||
BUILDS+="owhw/dfu owhw/cardem "
|
BUILDS+="owhw/dfu owhw/cardem "
|
||||||
|
|
||||||
@@ -71,13 +71,13 @@ if [ "x$publish" = "x--publish" ]; then
|
|||||||
$TOPDIR/contrib/prepare_upload.sh
|
$TOPDIR/contrib/prepare_upload.sh
|
||||||
|
|
||||||
cat > "/build/known_hosts" <<EOF
|
cat > "/build/known_hosts" <<EOF
|
||||||
[rita.osmocom.org]:48 ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDDgQ9HntlpWNmh953a2Gc8NysKE4orOatVT1wQkyzhARnfYUerRuwyNr1GqMyBKdSI9amYVBXJIOUFcpV81niA7zQRUs66bpIMkE9/rHxBd81SkorEPOIS84W4vm3SZtuNqa+fADcqe88Hcb0ZdTzjKILuwi19gzrQyME2knHY71EOETe9Yow5RD2hTIpB5ecNxI0LUKDq+Ii8HfBvndPBIr0BWYDugckQ3Bocf+yn/tn2/GZieFEyFpBGF/MnLbAAfUKIdeyFRX7ufaiWWz5yKAfEhtziqdAGZaXNaLG6gkpy3EixOAy6ZXuTAk3b3Y0FUmDjhOHllbPmTOcKMry9
|
[ftp.osmocom.org]:48 ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDDgQ9HntlpWNmh953a2Gc8NysKE4orOatVT1wQkyzhARnfYUerRuwyNr1GqMyBKdSI9amYVBXJIOUFcpV81niA7zQRUs66bpIMkE9/rHxBd81SkorEPOIS84W4vm3SZtuNqa+fADcqe88Hcb0ZdTzjKILuwi19gzrQyME2knHY71EOETe9Yow5RD2hTIpB5ecNxI0LUKDq+Ii8HfBvndPBIr0BWYDugckQ3Bocf+yn/tn2/GZieFEyFpBGF/MnLbAAfUKIdeyFRX7ufaiWWz5yKAfEhtziqdAGZaXNaLG6gkpy3EixOAy6ZXuTAk3b3Y0FUmDjhOHllbPmTOcKMry9
|
||||||
[rita.osmocom.org]:48 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBPdWn1kEousXuKsZ+qJEZTt/NSeASxCrUfNDW3LWtH+d8Ust7ZuKp/vuyG+5pe5pwpPOgFu7TjN+0lVjYJVXH54=
|
[ftp.osmocom.org]:48 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBPdWn1kEousXuKsZ+qJEZTt/NSeASxCrUfNDW3LWtH+d8Ust7ZuKp/vuyG+5pe5pwpPOgFu7TjN+0lVjYJVXH54=
|
||||||
[rita.osmocom.org]:48 ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIK8iivY70EiR5NiGChV39gRLjNpC8lvu1ZdHtdMw2zuX
|
[ftp.osmocom.org]:48 ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIK8iivY70EiR5NiGChV39gRLjNpC8lvu1ZdHtdMw2zuX
|
||||||
EOF
|
EOF
|
||||||
SSH_COMMAND="ssh -o 'UserKnownHostsFile=/build/known_hosts' -p 48"
|
SSH_COMMAND="ssh -o 'UserKnownHostsFile=/build/known_hosts' -p 48"
|
||||||
rsync --archive --verbose --compress --delete --rsh "$SSH_COMMAND" $TOPDIR/firmware/bin/*-latest.{bin,elf} binaries@rita.osmocom.org:web-files/simtrace2/firmware/latest/
|
rsync --archive --verbose --compress --delete --rsh "$SSH_COMMAND" $TOPDIR/firmware/bin/*-latest.{bin,elf} binaries@ftp.osmocom.org:web-files/simtrace2/firmware/latest/
|
||||||
rsync --archive --verbose --compress --rsh "$SSH_COMMAND" --exclude $TOPDIR/firmware/bin/*-latest.{bin,elf} $TOPDIR/firmware/bin/*-*-*-*.{bin,elf} binaries@rita.osmocom.org:web-files/simtrace2/firmware/all/
|
rsync --archive --verbose --compress --rsh "$SSH_COMMAND" --exclude $TOPDIR/firmware/bin/*-latest.{bin,elf} $TOPDIR/firmware/bin/*-*-*-*.{bin,elf} binaries@ftp.osmocom.org:web-files/simtrace2/firmware/all/
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo
|
echo
|
||||||
|
|||||||
@@ -178,6 +178,14 @@ CFLAGS += -ffunction-sections -g $(OPTIMIZATION) $(INCLUDES) -D$(CHIP) -DTRACE_L
|
|||||||
CFLAGS += -DGIT_VERSION=\"$(GIT_VERSION)\"
|
CFLAGS += -DGIT_VERSION=\"$(GIT_VERSION)\"
|
||||||
CFLAGS += -DBOARD=\"$(BOARD)\" -DBOARD_$(BOARD)
|
CFLAGS += -DBOARD=\"$(BOARD)\" -DBOARD_$(BOARD)
|
||||||
CFLAGS += -DAPPLICATION=\"$(APP)\" -DAPPLICATION_$(APP)
|
CFLAGS += -DAPPLICATION=\"$(APP)\" -DAPPLICATION_$(APP)
|
||||||
|
|
||||||
|
# Disable stack protector by default (OS#5081)
|
||||||
|
ifeq ($(STACK_PROTECTOR), 1)
|
||||||
|
CFLAGS += -fstack-protector
|
||||||
|
else
|
||||||
|
CFLAGS += -fno-stack-protector
|
||||||
|
endif
|
||||||
|
|
||||||
ASFLAGS = -mcpu=cortex-m3 -mthumb -Wall -g $(OPTIMIZATION) $(INCLUDES) -D$(CHIP) -D__ASSEMBLY__
|
ASFLAGS = -mcpu=cortex-m3 -mthumb -Wall -g $(OPTIMIZATION) $(INCLUDES) -D$(CHIP) -D__ASSEMBLY__
|
||||||
LDFLAGS = -mcpu=cortex-m3 -mthumb -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--entry=ResetException -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align -Wl,--print-memory-usage -Wl,--no-undefined $(LIB)
|
LDFLAGS = -mcpu=cortex-m3 -mthumb -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--entry=ResetException -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align -Wl,--print-memory-usage -Wl,--no-undefined $(LIB)
|
||||||
#LD_OPTIONAL=-Wl,--print-gc-sections -Wl,--stats
|
#LD_OPTIONAL=-Wl,--print-gc-sections -Wl,--stats
|
||||||
|
|||||||
@@ -153,10 +153,14 @@
|
|||||||
|
|
||||||
/** Supported modes */
|
/** Supported modes */
|
||||||
/* SIMtrace board supports sniffer mode */
|
/* SIMtrace board supports sniffer mode */
|
||||||
|
#ifdef APPLICATION_trace
|
||||||
#define HAVE_SNIFFER
|
#define HAVE_SNIFFER
|
||||||
|
#endif
|
||||||
/* SIMtrace board supports CCID mode */
|
/* SIMtrace board supports CCID mode */
|
||||||
//#define HAVE_CCID
|
//#define HAVE_CCID
|
||||||
/* SIMtrace board supports card emulation mode */
|
/* SIMtrace board supports card emulation mode */
|
||||||
//#define HAVE_CARDEM
|
#ifdef APPLICATION_cardem
|
||||||
|
#define HAVE_CARDEM
|
||||||
|
#endif
|
||||||
/* SIMtrace board supports man-in-the-middle mode */
|
/* SIMtrace board supports man-in-the-middle mode */
|
||||||
//#define HAVE_MITM
|
//#define HAVE_MITM
|
||||||
|
|||||||
@@ -89,7 +89,7 @@
|
|||||||
/// \param condition Condition to verify.
|
/// \param condition Condition to verify.
|
||||||
#define ASSERT(condition) { \
|
#define ASSERT(condition) { \
|
||||||
if (!(condition)) { \
|
if (!(condition)) { \
|
||||||
printf("-F- ASSERT: %s %s:%d\n\r", #condition, __BASE_FILE__, __LINE__); \
|
printf_sync("-F- ASSERT: %s %s:%d\n\r", #condition, __BASE_FILE__, __LINE__); \
|
||||||
while (1); \
|
while (1); \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ enum card_io {
|
|||||||
|
|
||||||
/** initialise card slot
|
/** initialise card slot
|
||||||
* @param[in] slot_num slot number (arbitrary number)
|
* @param[in] slot_num slot number (arbitrary number)
|
||||||
* @param[in] tc_chan timer counter channel (to measure the ETU)
|
|
||||||
* @param[in] uart_chan UART peripheral channel
|
* @param[in] uart_chan UART peripheral channel
|
||||||
* @param[in] in_ep USB IN end point number
|
* @param[in] in_ep USB IN end point number
|
||||||
* @param[in] irq_ep USB INTerrupt end point number
|
* @param[in] irq_ep USB INTerrupt end point number
|
||||||
@@ -40,7 +39,7 @@ enum card_io {
|
|||||||
* @param[in] clocked initial CLK signat state (true = active)
|
* @param[in] clocked initial CLK signat state (true = active)
|
||||||
* @return main card handle reference
|
* @return main card handle reference
|
||||||
*/
|
*/
|
||||||
struct card_handle *card_emu_init(uint8_t slot_num, uint8_t tc_chan, uint8_t uart_chan, uint8_t in_ep, uint8_t irq_ep, bool vcc_active, bool in_reset, bool clocked);
|
struct card_handle *card_emu_init(uint8_t slot_num, uint8_t uart_chan, uint8_t in_ep, uint8_t irq_ep, bool vcc_active, bool in_reset, bool clocked);
|
||||||
|
|
||||||
/* process a single byte received from the reader */
|
/* process a single byte received from the reader */
|
||||||
void card_emu_process_rx_byte(struct card_handle *ch, uint8_t byte);
|
void card_emu_process_rx_byte(struct card_handle *ch, uint8_t byte);
|
||||||
|
|||||||
@@ -230,9 +230,15 @@ struct cardemu_usb_msg_status {
|
|||||||
uint32_t flags;
|
uint32_t flags;
|
||||||
/* phone-applied target voltage in mV */
|
/* phone-applied target voltage in mV */
|
||||||
uint16_t voltage_mv;
|
uint16_t voltage_mv;
|
||||||
/* Fi/Di related information */
|
/* F/D related information. Not actual Fn/Dn values but indexes into tables! */
|
||||||
uint8_t F_index; /* <! Index to ISO7816-3 Table 7 (F and f_max values) */
|
union {
|
||||||
uint8_t D_index; /* <! Index into ISO7816-3 Table 8 (D value) */
|
uint8_t F_index; /* <! Index to ISO7816-3 Table 7 (F and f_max values) */
|
||||||
|
uint8_t fi; /* <! old, wrong name for API compatibility */
|
||||||
|
};
|
||||||
|
union {
|
||||||
|
uint8_t D_index; /* <! Index to ISO7816-3 Table 8 (D value) */
|
||||||
|
uint8_t di; /* <! old, wrong name for API compatibility */
|
||||||
|
};
|
||||||
uint8_t wi; /* <! Waiting Integer as defined in ISO7816-3 Section 10.2 */
|
uint8_t wi; /* <! Waiting Integer as defined in ISO7816-3 Section 10.2 */
|
||||||
uint32_t waiting_time; /* <! Waiting Time in etu as defined in ISO7816-3 Section 8.1 */
|
uint32_t waiting_time; /* <! Waiting Time in etu as defined in ISO7816-3 Section 8.1 */
|
||||||
} __attribute__ ((packed));
|
} __attribute__ ((packed));
|
||||||
|
|||||||
@@ -176,7 +176,6 @@ struct card_handle {
|
|||||||
* \note this depends on Fi, Di, and WI if T=0 is used */
|
* \note this depends on Fi, Di, and WI if T=0 is used */
|
||||||
uint32_t waiting_time; /* in etu */
|
uint32_t waiting_time; /* in etu */
|
||||||
|
|
||||||
uint8_t tc_chan; /* TC channel number */
|
|
||||||
uint8_t uart_chan; /* UART channel */
|
uint8_t uart_chan; /* UART channel */
|
||||||
|
|
||||||
uint8_t in_ep; /* USB IN EP */
|
uint8_t in_ep; /* USB IN EP */
|
||||||
@@ -431,7 +430,7 @@ static void card_set_state(struct card_handle *ch,
|
|||||||
/* update waiting time to initial waiting time */
|
/* update waiting time to initial waiting time */
|
||||||
ch->waiting_time = ISO7816_3_INIT_WTIME;
|
ch->waiting_time = ISO7816_3_INIT_WTIME;
|
||||||
/* set initial waiting time */
|
/* set initial waiting time */
|
||||||
card_emu_uart_update_wt(ch->tc_chan, ch->waiting_time);
|
card_emu_uart_update_wt(ch->uart_chan, ch->waiting_time);
|
||||||
/* Set ATR sub-state to initial state */
|
/* Set ATR sub-state to initial state */
|
||||||
ch->atr.idx = 0;
|
ch->atr.idx = 0;
|
||||||
/* enable USART transmission to reader */
|
/* enable USART transmission to reader */
|
||||||
@@ -506,8 +505,11 @@ static int tx_byte_atr(struct card_handle *ch)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* update waiting time (see ISO 7816-3 10.2) */
|
/* update waiting time (see ISO 7816-3 10.2). We can drop the Fi
|
||||||
ch->waiting_time = ch->wi * 960 * iso7816_3_fi_table[ch->F_index];
|
* multiplier as we store the waiting time in units of 'etu', and
|
||||||
|
* don't really care what the number of clock cycles or the absolute
|
||||||
|
* wall clock time is */
|
||||||
|
ch->waiting_time = ch->wi * 960;
|
||||||
/* go to next state */
|
/* go to next state */
|
||||||
card_set_state(ch, ISO_S_WAIT_TPDU);
|
card_set_state(ch, ISO_S_WAIT_TPDU);
|
||||||
return 0;
|
return 0;
|
||||||
@@ -1245,7 +1247,7 @@ int card_emu_set_config(struct card_handle *ch, const struct cardemu_usb_msg_con
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct card_handle *card_emu_init(uint8_t slot_num, uint8_t tc_chan, uint8_t uart_chan, uint8_t in_ep, uint8_t irq_ep, bool vcc_active, bool in_reset, bool clocked)
|
struct card_handle *card_emu_init(uint8_t slot_num, uint8_t uart_chan, uint8_t in_ep, uint8_t irq_ep, bool vcc_active, bool in_reset, bool clocked)
|
||||||
{
|
{
|
||||||
struct card_handle *ch;
|
struct card_handle *ch;
|
||||||
|
|
||||||
@@ -1270,7 +1272,6 @@ struct card_handle *card_emu_init(uint8_t slot_num, uint8_t tc_chan, uint8_t uar
|
|||||||
ch->Di_index = ch->D_index = 1;
|
ch->Di_index = ch->D_index = 1;
|
||||||
ch->wi = ISO7816_3_DEFAULT_WI;
|
ch->wi = ISO7816_3_DEFAULT_WI;
|
||||||
|
|
||||||
ch->tc_chan = tc_chan;
|
|
||||||
ch->uart_chan = uart_chan;
|
ch->uart_chan = uart_chan;
|
||||||
ch->waiting_time = ISO7816_3_INIT_WTIME;
|
ch->waiting_time = ISO7816_3_INIT_WTIME;
|
||||||
|
|
||||||
|
|||||||
@@ -213,6 +213,22 @@ int card_emu_uart_tx(uint8_t uart_chan, uint8_t byte)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static uint16_t compute_next_timeout(struct cardem_inst *ci)
|
||||||
|
{
|
||||||
|
uint32_t want_to_expire;
|
||||||
|
|
||||||
|
if (ci->wt.total == 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (!ci->wt.half_time_notified) {
|
||||||
|
/* we need to make sure to expire after half the total waiting time */
|
||||||
|
OSMO_ASSERT(ci->wt.remaining > (ci->wt.total / 2));
|
||||||
|
want_to_expire = ci->wt.remaining - (ci->wt.total / 2);
|
||||||
|
} else
|
||||||
|
want_to_expire = ci->wt.remaining;
|
||||||
|
/* if value exceeds the USART TO range, use the maximum possible value for one round */
|
||||||
|
return OSMO_MIN(want_to_expire, 0xffff);
|
||||||
|
}
|
||||||
|
|
||||||
/*! common handler if interrupt was received.
|
/*! common handler if interrupt was received.
|
||||||
* \param[in] inst_num Instance number, range 0..1 (some boards only '0' permitted) */
|
* \param[in] inst_num Instance number, range 0..1 (some boards only '0' permitted) */
|
||||||
@@ -256,6 +272,9 @@ static void usart_irq_rx(uint8_t inst_num)
|
|||||||
* how many etu have expired since we last sent a byte. See section
|
* how many etu have expired since we last sent a byte. See section
|
||||||
* 33.7.3.11 "Receiver Time-out" of the SAM3S8 Data Sheet */
|
* 33.7.3.11 "Receiver Time-out" of the SAM3S8 Data Sheet */
|
||||||
if (csr & US_CSR_TIMEOUT) {
|
if (csr & US_CSR_TIMEOUT) {
|
||||||
|
/* clear timeout flag (and stop timeout until next character is received) */
|
||||||
|
usart->US_CR |= US_CR_STTTO;
|
||||||
|
|
||||||
/* RX has been inactive for some time */
|
/* RX has been inactive for some time */
|
||||||
if (ci->wt.remaining <= (usart->US_RTOR & 0xffff)) {
|
if (ci->wt.remaining <= (usart->US_RTOR & 0xffff)) {
|
||||||
/* waiting time is over; will stop the timer */
|
/* waiting time is over; will stop the timer */
|
||||||
@@ -268,17 +287,26 @@ static void usart_irq_rx(uint8_t inst_num)
|
|||||||
if (ci->wt.remaining == 0) {
|
if (ci->wt.remaining == 0) {
|
||||||
/* let the FSM know that WT has expired */
|
/* let the FSM know that WT has expired */
|
||||||
card_emu_wtime_expired(ci->ch);
|
card_emu_wtime_expired(ci->ch);
|
||||||
} else if (ci->wt.remaining <= ci->wt.total / 2 && !ci->wt.half_time_notified) {
|
/* don't automatically re-start in this case */
|
||||||
/* let the FS know that half of the WT has expired */
|
} else {
|
||||||
card_emu_wtime_half_expired(ci->ch);
|
bool half_time_just_reached = false;
|
||||||
ci->wt.half_time_notified = true;
|
|
||||||
|
if (ci->wt.remaining <= ci->wt.total / 2 && !ci->wt.half_time_notified) {
|
||||||
|
ci->wt.half_time_notified = true;
|
||||||
|
/* don't immediately call card_emu_wtime_half_expired(), as that
|
||||||
|
* in turn may calls card_emu_uart_update_wt() which will change
|
||||||
|
* the timeout but would be overridden 4 lines below */
|
||||||
|
half_time_just_reached = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* update the counter no matter if we reached half time or not */
|
||||||
|
usart->US_RTOR = compute_next_timeout(ci);
|
||||||
|
/* restart the counter (if wt is 0, the timeout is not started) */
|
||||||
|
usart->US_CR |= US_CR_RETTO;
|
||||||
|
|
||||||
|
if (half_time_just_reached)
|
||||||
|
card_emu_wtime_half_expired(ci->ch);
|
||||||
}
|
}
|
||||||
/* if value exceeds the USART TO range, use the maximum for now */
|
|
||||||
usart->US_RTOR = OSMO_MIN(ci->wt.remaining, 0xffff);
|
|
||||||
/* clear timeout flag (and stop timeout until next character is received) */
|
|
||||||
usart->US_CR |= US_CR_STTTO;
|
|
||||||
/* restart the counter (it wt is 0, the timeout is not started) */
|
|
||||||
usart->US_CR |= US_CR_RETTO;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -317,10 +345,14 @@ void card_emu_uart_update_wt(uint8_t uart_chan, uint32_t wt)
|
|||||||
struct cardem_inst *ci = &cardem_inst[uart_chan];
|
struct cardem_inst *ci = &cardem_inst[uart_chan];
|
||||||
Usart *usart = get_usart_by_chan(uart_chan);
|
Usart *usart = get_usart_by_chan(uart_chan);
|
||||||
|
|
||||||
|
if (ci->wt.total != wt) {
|
||||||
|
TRACE_DEBUG("%u: USART WT changed from %lu to %lu ETU\r\n", uart_chan,
|
||||||
|
ci->wt.total, wt);
|
||||||
|
}
|
||||||
|
|
||||||
ci->wt.total = wt;
|
ci->wt.total = wt;
|
||||||
/* reset and start the timer */
|
/* reset and start the timer */
|
||||||
card_emu_uart_reset_wt(uart_chan);
|
card_emu_uart_reset_wt(uart_chan);
|
||||||
TRACE_INFO("%u: USART WT set to %lu ETU\r\n", uart_chan, wt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Reset and re-start waiting timeout count down on USART peripheral.
|
/*! Reset and re-start waiting timeout count down on USART peripheral.
|
||||||
@@ -334,8 +366,7 @@ void card_emu_uart_reset_wt(uint8_t uart_chan)
|
|||||||
/* FIXME: guard against race with interrupt handler */
|
/* FIXME: guard against race with interrupt handler */
|
||||||
ci->wt.remaining = ci->wt.total;
|
ci->wt.remaining = ci->wt.total;
|
||||||
ci->wt.half_time_notified = false;
|
ci->wt.half_time_notified = false;
|
||||||
/* if value exceeds the USART TO range, use the maximum for now */
|
usart->US_RTOR = compute_next_timeout(ci);
|
||||||
usart->US_RTOR = OSMO_MIN(ci->wt.remaining, 0xffff);
|
|
||||||
/* restart the counter (if wt is 0, the timeout is not started) */
|
/* restart the counter (if wt is 0, the timeout is not started) */
|
||||||
usart->US_CR |= US_CR_RETTO;
|
usart->US_CR |= US_CR_RETTO;
|
||||||
}
|
}
|
||||||
@@ -520,20 +551,7 @@ void mode_cardemu_init(void)
|
|||||||
|
|
||||||
/* configure USART as ISO-7816 slave (e.g. card) */
|
/* configure USART as ISO-7816 slave (e.g. card) */
|
||||||
ISO7816_Init(&cardem_inst[0].usart_info, CLK_SLAVE);
|
ISO7816_Init(&cardem_inst[0].usart_info, CLK_SLAVE);
|
||||||
#ifdef BOARD_simtrace
|
|
||||||
/* simtrace board uses uart timeouts */
|
|
||||||
|
|
||||||
/* don't use receive timeout timer for now */
|
|
||||||
cardem_inst[0].usart_info.base->US_RTOR = 0;
|
|
||||||
/* enable interrupts to indicate when data has been received or timeout occurred */
|
|
||||||
USART_EnableIt(cardem_inst[0].usart_info.base, US_IER_RXRDY | US_IER_TIMEOUT);
|
|
||||||
#else
|
|
||||||
/* enable interrupts to indicate when data has been received */
|
|
||||||
USART_EnableIt(cardem_inst[0].usart_info.base, US_IER_RXRDY );
|
|
||||||
#endif
|
|
||||||
/* enable interrupt requests for the USART peripheral */
|
|
||||||
NVIC_EnableIRQ(USART1_IRQn);
|
NVIC_EnableIRQ(USART1_IRQn);
|
||||||
|
|
||||||
PIO_ConfigureIt(&pin_usim1_rst, usim1_rst_irqhandler);
|
PIO_ConfigureIt(&pin_usim1_rst, usim1_rst_irqhandler);
|
||||||
PIO_EnableIt(&pin_usim1_rst);
|
PIO_EnableIt(&pin_usim1_rst);
|
||||||
|
|
||||||
@@ -549,7 +567,7 @@ void mode_cardemu_init(void)
|
|||||||
do {} while (!adc_triggered); /* wait for first ADC reading */
|
do {} while (!adc_triggered); /* wait for first ADC reading */
|
||||||
#endif /* DETECT_VCC_BY_ADC */
|
#endif /* DETECT_VCC_BY_ADC */
|
||||||
|
|
||||||
cardem_inst[0].ch = card_emu_init(0, 2, 0, SIMTRACE_CARDEM_USB_EP_USIM1_DATAIN,
|
cardem_inst[0].ch = card_emu_init(0, 0, SIMTRACE_CARDEM_USB_EP_USIM1_DATAIN,
|
||||||
SIMTRACE_CARDEM_USB_EP_USIM1_INT, cardem_inst[0].vcc_active,
|
SIMTRACE_CARDEM_USB_EP_USIM1_INT, cardem_inst[0].vcc_active,
|
||||||
cardem_inst[0].rst_active, cardem_inst[0].vcc_active);
|
cardem_inst[0].rst_active, cardem_inst[0].vcc_active);
|
||||||
sim_switch_use_physical(0, 1);
|
sim_switch_use_physical(0, 1);
|
||||||
@@ -572,7 +590,7 @@ void mode_cardemu_init(void)
|
|||||||
do {} while (!adc_triggered); /* wait for first ADC reading */
|
do {} while (!adc_triggered); /* wait for first ADC reading */
|
||||||
#endif /* DETECT_VCC_BY_ADC */
|
#endif /* DETECT_VCC_BY_ADC */
|
||||||
|
|
||||||
cardem_inst[1].ch = card_emu_init(1, 0, 1, SIMTRACE_CARDEM_USB_EP_USIM2_DATAIN,
|
cardem_inst[1].ch = card_emu_init(1, 1, SIMTRACE_CARDEM_USB_EP_USIM2_DATAIN,
|
||||||
SIMTRACE_CARDEM_USB_EP_USIM2_INT, cardem_inst[1].vcc_active,
|
SIMTRACE_CARDEM_USB_EP_USIM2_INT, cardem_inst[1].vcc_active,
|
||||||
cardem_inst[1].rst_active, cardem_inst[1].vcc_active);
|
cardem_inst[1].rst_active, cardem_inst[1].vcc_active);
|
||||||
sim_switch_use_physical(1, 1);
|
sim_switch_use_physical(1, 1);
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ static osmo_panic_handler_t osmo_panic_handler = (void*)0;
|
|||||||
__attribute__ ((format (printf, 1, 0)))
|
__attribute__ ((format (printf, 1, 0)))
|
||||||
static void osmo_panic_default(const char *fmt, va_list args)
|
static void osmo_panic_default(const char *fmt, va_list args)
|
||||||
{
|
{
|
||||||
vfprintf(stderr, fmt, args);
|
vfprintf_sync(stderr, fmt, args);
|
||||||
osmo_generate_backtrace();
|
osmo_generate_backtrace();
|
||||||
assert(0);
|
assert(0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,20 @@
|
|||||||
#define PHONE_INT 2
|
#define PHONE_INT 2
|
||||||
#define PHONE_DATAOUT 3
|
#define PHONE_DATAOUT 3
|
||||||
|
|
||||||
|
/* stub for stdio */
|
||||||
|
signed int printf_sync(const char *pFormat, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
signed int result;
|
||||||
|
|
||||||
|
va_start(ap, pFormat);
|
||||||
|
result = vprintf(pFormat, ap);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
* stub functions required by card_emu.c
|
* stub functions required by card_emu.c
|
||||||
***********************************************************************/
|
***********************************************************************/
|
||||||
@@ -50,6 +64,9 @@ void card_emu_uart_enable(uint8_t uart_chan, uint8_t rxtx)
|
|||||||
case ENABLE_TX:
|
case ENABLE_TX:
|
||||||
rts = "TX";
|
rts = "TX";
|
||||||
break;
|
break;
|
||||||
|
case ENABLE_TX_TIMER_ONLY:
|
||||||
|
rts = "TX-TIMER-ONLY";
|
||||||
|
break;
|
||||||
case ENABLE_RX:
|
case ENABLE_RX:
|
||||||
rts = "RX";
|
rts = "RX";
|
||||||
break;
|
break;
|
||||||
@@ -66,29 +83,14 @@ void card_emu_uart_interrupt(uint8_t uart_chan)
|
|||||||
printf("uart_interrupt(uart_chan=%u)\n", uart_chan);
|
printf("uart_interrupt(uart_chan=%u)\n", uart_chan);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tc_etu_set_wtime(uint8_t tc_chan, uint16_t wtime)
|
void card_emu_uart_update_wt(uint8_t uart_chan, uint32_t wt)
|
||||||
{
|
{
|
||||||
printf("tc_etu_set_wtime(tc_chan=%u, wtime=%u)\n", tc_chan, wtime);
|
printf("%s(uart_chan=%u, wtime=%u)\n", __func__, uart_chan, wt);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tc_etu_set_etu(uint8_t tc_chan, uint16_t etu)
|
void card_emu_uart_reset_wt(uint8_t uart_chan)
|
||||||
{
|
{
|
||||||
printf("tc_etu_set_etu(tc_chan=%u, etu=%u)\n", tc_chan, etu);
|
printf("%s(uart_chan=%u\n", __func__, uart_chan);
|
||||||
}
|
|
||||||
|
|
||||||
void tc_etu_init(uint8_t chan_nr, void *handle)
|
|
||||||
{
|
|
||||||
printf("tc_etu_init(tc_chan=%u)\n", chan_nr);
|
|
||||||
}
|
|
||||||
|
|
||||||
void tc_etu_enable(uint8_t chan_nr)
|
|
||||||
{
|
|
||||||
printf("tc_etu_enable(tc_chan=%u)\n", chan_nr);
|
|
||||||
}
|
|
||||||
|
|
||||||
void tc_etu_disable(uint8_t chan_nr)
|
|
||||||
{
|
|
||||||
printf("tc_etu_disable(tc_chan=%u)\n", chan_nr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -136,7 +138,7 @@ static void io_start_card(struct card_handle *ch)
|
|||||||
/* release from reset and verify th ATR */
|
/* release from reset and verify th ATR */
|
||||||
card_emu_io_statechg(ch, CARD_IO_RST, 0);
|
card_emu_io_statechg(ch, CARD_IO_RST, 0);
|
||||||
/* simulate waiting time before ATR expired */
|
/* simulate waiting time before ATR expired */
|
||||||
tc_etu_wtime_expired(ch);
|
card_emu_wtime_expired(ch);
|
||||||
verify_atr(ch);
|
verify_atr(ch);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -408,7 +410,7 @@ int main(int argc, char **argv)
|
|||||||
struct card_handle *ch;
|
struct card_handle *ch;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
ch = card_emu_init(0, 23, 42, PHONE_DATAIN, PHONE_INT, false, true, false);
|
ch = card_emu_init(0, 42, PHONE_DATAIN, PHONE_INT, false, true, false);
|
||||||
assert(ch);
|
assert(ch);
|
||||||
|
|
||||||
usb_buf_init();
|
usb_buf_init();
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* simtrace2-cardem-pcsc - main program for the host PC to provide a remote SIM
|
/* simtrace2-cardem-pcsc - main program for the host PC to provide a remote SIM
|
||||||
* using the SIMtrace 2 firmware in card emulation mode
|
* using the SIMtrace 2 firmware in card emulation mode
|
||||||
*
|
*
|
||||||
* (C) 2016-2020 by Harald Welte <hwelte@hmw-consulting.de>
|
* (C) 2016-2021 by Harald Welte <hwelte@hmw-consulting.de>
|
||||||
* (C) 2018, sysmocom -s.f.m.c. GmbH, Author: Kevin Redon <kredon@sysmocom.de>
|
* (C) 2018, sysmocom -s.f.m.c. GmbH, Author: Kevin Redon <kredon@sysmocom.de>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or
|
* This program is free software; you can redistribute it and/or
|
||||||
@@ -51,29 +51,8 @@
|
|||||||
#include <osmocom/sim/class_tables.h>
|
#include <osmocom/sim/class_tables.h>
|
||||||
#include <osmocom/sim/sim.h>
|
#include <osmocom/sim/sim.h>
|
||||||
|
|
||||||
#define ATR_MAX_LEN 33
|
|
||||||
|
|
||||||
#define LOGCI(ci, lvl, fmt, args ...) printf(fmt, ## args)
|
#define LOGCI(ci, lvl, fmt, args ...) printf(fmt, ## args)
|
||||||
|
|
||||||
/* reasonable ATR offering all protocols and voltages
|
|
||||||
* smartphones might not care, but other readers do
|
|
||||||
*
|
|
||||||
* TS = 0x3B Direct Convention
|
|
||||||
* T0 = 0x80 Y(1): b1000, K: 0 (historical bytes)
|
|
||||||
* TD(1) = 0x80 Y(i+1) = b1000, Protocol T=0
|
|
||||||
* ----
|
|
||||||
* TD(2) = 0x81 Y(i+1) = b1000, Protocol T=1
|
|
||||||
* ----
|
|
||||||
* TD(3) = 0x1F Y(i+1) = b0001, Protocol T=15
|
|
||||||
* ----
|
|
||||||
* TA(4) = 0xC7 Clock stop: no preference - Class accepted by the card: (3G) A 5V B 3V C 1.8V
|
|
||||||
* ----
|
|
||||||
* Historical bytes
|
|
||||||
* TCK = 0x59 correct checksum
|
|
||||||
*/
|
|
||||||
#define DEFAULT_ATR_STR "3B8080811FC759"
|
|
||||||
|
|
||||||
|
|
||||||
static void atr_update_csum(uint8_t *atr, unsigned int atr_len)
|
static void atr_update_csum(uint8_t *atr, unsigned int atr_len)
|
||||||
{
|
{
|
||||||
uint8_t csum = 0;
|
uint8_t csum = 0;
|
||||||
@@ -200,7 +179,7 @@ static int process_irq_status(struct osmo_st2_cardem_inst *ci, const uint8_t *bu
|
|||||||
const struct cardemu_usb_msg_status *status = (struct cardemu_usb_msg_status *) buf;
|
const struct cardemu_usb_msg_status *status = (struct cardemu_usb_msg_status *) buf;
|
||||||
|
|
||||||
LOGCI(ci, LOGL_INFO, "SIMtrace IRQ STATUS: flags=0x%x, fi=%u, di=%u, wi=%u wtime=%u\n",
|
LOGCI(ci, LOGL_INFO, "SIMtrace IRQ STATUS: flags=0x%x, fi=%u, di=%u, wi=%u wtime=%u\n",
|
||||||
status->flags, status->F_index, status->D_index, status->wi,
|
status->flags, status->fi, status->di, status->wi,
|
||||||
status->waiting_time);
|
status->waiting_time);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -415,9 +394,9 @@ int main(int argc, char **argv)
|
|||||||
int rc;
|
int rc;
|
||||||
int c, ret = 1;
|
int c, ret = 1;
|
||||||
int skip_atr = 0;
|
int skip_atr = 0;
|
||||||
char *atr = DEFAULT_ATR_STR;
|
char *atr = NULL;
|
||||||
uint8_t real_atr[ATR_MAX_LEN];
|
uint8_t override_atr[OSIM_MAX_ATR_LEN];
|
||||||
int atr_len;
|
int override_atr_len = 0;
|
||||||
int keep_running = 0;
|
int keep_running = 0;
|
||||||
int if_num = 0, vendor_id = -1, product_id = -1;
|
int if_num = 0, vendor_id = -1, product_id = -1;
|
||||||
int config_id = -1, altsetting = 0, addr = -1;
|
int config_id = -1, altsetting = 0, addr = -1;
|
||||||
@@ -484,11 +463,13 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
atr_len = osmo_hexparse(atr,real_atr,ATR_MAX_LEN);
|
if (atr) {
|
||||||
if (atr_len < 2) {
|
override_atr_len = osmo_hexparse(atr, override_atr, sizeof(override_atr));
|
||||||
fprintf(stderr, "Invalid ATR - please omit a leading 0x and only use valid hex "
|
if (override_atr_len < 2) {
|
||||||
"digits and whitespace. ATRs need to be between 2 and 33 bytes long.\n");
|
fprintf(stderr, "Invalid ATR - please omit a leading 0x and only use valid hex "
|
||||||
goto do_exit;
|
"digits and whitespace. ATRs need to be between 2 and 33 bytes long.\n");
|
||||||
|
goto do_exit;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vendor_id < 0 || product_id < 0) {
|
if (vendor_id < 0 || product_id < 0) {
|
||||||
@@ -545,20 +526,20 @@ int main(int argc, char **argv)
|
|||||||
transp->usb_devh = osmo_libusb_open_claim_interface(NULL, NULL, ifm);
|
transp->usb_devh = osmo_libusb_open_claim_interface(NULL, NULL, ifm);
|
||||||
if (!transp->usb_devh) {
|
if (!transp->usb_devh) {
|
||||||
fprintf(stderr, "can't open USB device\n");
|
fprintf(stderr, "can't open USB device\n");
|
||||||
goto close_exit;
|
goto close;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = libusb_claim_interface(transp->usb_devh, if_num);
|
rc = libusb_claim_interface(transp->usb_devh, if_num);
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
fprintf(stderr, "can't claim interface %d; rc=%d\n", if_num, rc);
|
fprintf(stderr, "can't claim interface %d; rc=%d\n", if_num, rc);
|
||||||
goto close_exit;
|
goto close;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = osmo_libusb_get_ep_addrs(transp->usb_devh, if_num, &transp->usb_ep.out,
|
rc = osmo_libusb_get_ep_addrs(transp->usb_devh, if_num, &transp->usb_ep.out,
|
||||||
&transp->usb_ep.in, &transp->usb_ep.irq_in);
|
&transp->usb_ep.in, &transp->usb_ep.irq_in);
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
fprintf(stderr, "can't obtain EP addrs; rc=%d\n", rc);
|
fprintf(stderr, "can't obtain EP addrs; rc=%d\n", rc);
|
||||||
goto close_exit;
|
goto close;
|
||||||
}
|
}
|
||||||
|
|
||||||
allocate_and_submit_irq(ci);
|
allocate_and_submit_irq(ci);
|
||||||
@@ -576,8 +557,14 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
if (!skip_atr) {
|
if (!skip_atr) {
|
||||||
/* set the ATR */
|
/* set the ATR */
|
||||||
atr_update_csum(real_atr, atr_len);
|
if (override_atr_len) {
|
||||||
osmo_st2_cardem_request_set_atr(ci, real_atr, atr_len);
|
/* user has specified an override-ATR */
|
||||||
|
atr_update_csum(override_atr, override_atr_len);
|
||||||
|
osmo_st2_cardem_request_set_atr(ci, override_atr, override_atr_len);
|
||||||
|
} else {
|
||||||
|
/* use the real ATR of the card */
|
||||||
|
osmo_st2_cardem_request_set_atr(ci, card->atr, card->atr_len);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* select remote (forwarded) SIM */
|
/* select remote (forwarded) SIM */
|
||||||
@@ -587,13 +574,20 @@ int main(int argc, char **argv)
|
|||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
libusb_release_interface(transp->usb_devh, 0);
|
libusb_release_interface(transp->usb_devh, 0);
|
||||||
close_exit:
|
|
||||||
if (transp->usb_devh)
|
close:
|
||||||
|
if (transp->usb_devh) {
|
||||||
libusb_close(transp->usb_devh);
|
libusb_close(transp->usb_devh);
|
||||||
|
transp->usb_devh = NULL;
|
||||||
|
}
|
||||||
if (keep_running)
|
if (keep_running)
|
||||||
sleep(1);
|
sleep(1);
|
||||||
} while (keep_running);
|
} while (keep_running);
|
||||||
|
|
||||||
|
close_exit:
|
||||||
|
if (transp->usb_devh)
|
||||||
|
libusb_close(transp->usb_devh);
|
||||||
|
|
||||||
libusb_exit(NULL);
|
libusb_exit(NULL);
|
||||||
do_exit:
|
do_exit:
|
||||||
return ret;
|
return ret;
|
||||||
|
|||||||
Reference in New Issue
Block a user