mirror of
https://gitea.osmocom.org/sim-card/simtrace2.git
synced 2026-08-14 22:41:59 +03:00
firmware: use the full 11 bit US_FIDI.FI_DI_RATIO
US_FIDI_FI_DI_RATIO_Msk is 0x7ff, cemu rejected >= 0x400 in emu_update_fidi() and masked with 0x3ff in card_emu_uart_update_fidi(), but update_fidi() used by the sniffer already used 0x7ff. -> ratios 1024..2047 are unusable in cemu, which is the entire upper half of ISO 7816-3 Table 7 at Di=1. A reader trying one of those in a PPS gets the proposal echoed and accepted, after which the card keeps transmitting at the old rate. FI_DI_RATIO is clock periods per bit -> larger ratio is a SLOWER link. The old check rejected slow values but accepted Fi=372/Di=64, ratio 5 !? Unify and use the register mask (= shifed by 0 so usable as value) and reject ratios that do not fit rather than truncating to garbage dividers. Change-Id: I6211dd5be7c5c5d2150af2aa37a403b33e6d340d
This commit is contained in:
@@ -376,7 +376,7 @@ static void emu_update_fidi(struct card_handle *ch)
|
||||
int rc;
|
||||
|
||||
rc = iso7816_3_compute_fd_ratio(ch->F_index, ch->D_index);
|
||||
if (rc > 0 && rc < 0x400) {
|
||||
if (rc > 0 && rc <= (US_FIDI_FI_DI_RATIO_Msk >> US_FIDI_FI_DI_RATIO_Pos)) {
|
||||
TRACE_INFO("%u: computed F(%u)/D(%u) ratio: %d\r\n", ch->num,
|
||||
ch->F_index, ch->D_index, rc);
|
||||
/* make sure UART uses new F/D ratio */
|
||||
|
||||
@@ -387,7 +387,7 @@ int card_emu_uart_update_fidi(uint8_t uart_chan, unsigned int fidi)
|
||||
Usart *usart = get_usart_by_chan(uart_chan);
|
||||
|
||||
usart->US_CR |= US_CR_RXDIS | US_CR_RSTRX;
|
||||
usart->US_FIDI = fidi & 0x3ff;
|
||||
usart->US_FIDI = US_FIDI_FI_DI_RATIO(fidi);
|
||||
usart->US_CR |= US_CR_RXEN | US_CR_STTTO;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -127,14 +127,14 @@ void update_fidi(Usart_info *usart, uint8_t fidi)
|
||||
uint8_t di = fidi & 0xf;
|
||||
int ratio = iso7816_3_compute_fd_ratio(fi, di);
|
||||
|
||||
if (ratio > 0 && ratio < 0x8000) {
|
||||
if (ratio > 0 && ratio <= (US_FIDI_FI_DI_RATIO_Msk >> US_FIDI_FI_DI_RATIO_Pos)) {
|
||||
/* make sure USART uses new F/D ratio */
|
||||
usart->base->US_CR |= US_CR_RXDIS | US_CR_RSTRX;
|
||||
/* disable write protection */
|
||||
if (usart->base->US_WPMR) {
|
||||
usart->base->US_WPMR = US_WPMR_WPKEY(0x555341);
|
||||
}
|
||||
usart->base->US_FIDI = (ratio & 0x7ff);
|
||||
usart->base->US_FIDI = US_FIDI_FI_DI_RATIO(ratio);
|
||||
usart->base->US_CR |= US_CR_RXEN | US_CR_STTTO;
|
||||
//TRACE_INFO("updated USART(%u) Fi(%u)/Di(%u) ratio(%d): %u\n\r", usart->id, fi, di, ratio, usart->base->US_FIDI);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user