aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@osmocom.org>2021-04-05 18:08:49 +0200
committerlaforge <laforge@osmocom.org>2021-04-08 21:28:37 +0000
commitc1ffc8a6039326a0f080b6d25408e8b06acaa73f (patch)
tree0897b6b17808722b8acd37724313e50703c179a0
parent79f0ea73a2da29b358e2488abe949d2a494af100 (diff)
iso7816_fidi: Add iso7816_3_ prefix to symbols; fix terminology
Fi/Di are not the index into the table, but the contents of the table as resolved by Fi_index / Di_index. Let's clarify the terminology. Change-Id: If364e08e7c9a3a9707e6d54b9267c6a7c088e415
-rw-r--r--firmware/libcommon/include/iso7816_fidi.h8
-rw-r--r--firmware/libcommon/source/card_emu.c6
-rw-r--r--firmware/libcommon/source/iso7816_fidi.c16
-rw-r--r--firmware/libcommon/source/simtrace_iso7816.c2
-rw-r--r--firmware/libcommon/source/sniffer.c5
5 files changed, 19 insertions, 18 deletions
diff --git a/firmware/libcommon/include/iso7816_fidi.h b/firmware/libcommon/include/iso7816_fidi.h
index c56478b..19483b0 100644
--- a/firmware/libcommon/include/iso7816_fidi.h
+++ b/firmware/libcommon/include/iso7816_fidi.h
@@ -21,10 +21,10 @@
#include <stdint.h>
/* Table 7 of ISO 7816-3:2006 */
-extern const uint16_t fi_table[];
+extern const uint16_t iso7816_3_fi_table[16];
/* Table 8 from ISO 7816-3:2006 */
-extern const uint8_t di_table[];
+extern const uint8_t iso7816_3_di_table[16];
-/* compute the F/D ratio based on Fi and Di values */
-int compute_fidi_ratio(uint8_t fi, uint8_t di);
+/* compute the F/D ratio based on F_index and D_index values */
+int iso7816_3_compute_fd_ratio(uint8_t f_index, uint8_t d_index);
diff --git a/firmware/libcommon/source/card_emu.c b/firmware/libcommon/source/card_emu.c
index 1193121..c5e4cfa 100644
--- a/firmware/libcommon/source/card_emu.c
+++ b/firmware/libcommon/source/card_emu.c
@@ -377,7 +377,7 @@ static void emu_update_fidi(struct card_handle *ch)
{
int rc;
- rc = compute_fidi_ratio(ch->F_index, ch->D_index);
+ rc = iso7816_3_compute_fd_ratio(ch->F_index, ch->D_index);
if (rc > 0 && rc < 0x400) {
TRACE_INFO("%u: computed F(%u)/D(%u) ratio: %d\r\n", ch->num,
ch->F_index, ch->D_index, rc);
@@ -508,7 +508,7 @@ static int tx_byte_atr(struct card_handle *ch)
}
}
/* update waiting time (see ISO 7816-3 10.2) */
- ch->waiting_time = ch->wi * 960 * fi_table[ch->F_index];
+ ch->waiting_time = ch->wi * 960 * iso7816_3_fi_table[ch->F_index];
tc_etu_set_wtime(ch->tc_chan, ch->waiting_time);
/* go to next state */
card_set_state(ch, ISO_S_WAIT_TPDU);
@@ -647,7 +647,7 @@ static int tx_byte_pts(struct card_handle *ch)
ch->F_index = byte >> 4;
ch->D_index = byte & 0xf;
TRACE_DEBUG("%u: found F=%u D=%u\r\n", ch->num,
- fi_table[ch->F_index], di_table[ch->D_index]);
+ iso7816_3_fi_table[ch->F_index], iso7816_3_di_table[ch->D_index]);
/* FIXME: if F or D are 0, become unresponsive to signal error condition */
break;
case PTS_S_WAIT_RESP_PTS2:
diff --git a/firmware/libcommon/source/iso7816_fidi.c b/firmware/libcommon/source/iso7816_fidi.c
index 1c70467..033a325 100644
--- a/firmware/libcommon/source/iso7816_fidi.c
+++ b/firmware/libcommon/source/iso7816_fidi.c
@@ -23,38 +23,38 @@
#include "iso7816_fidi.h"
/* Table 7 of ISO 7816-3:2006 */
-const uint16_t fi_table[] = {
+const uint16_t iso7816_3_fi_table[] = {
372, 372, 558, 744, 1116, 1488, 1860, 0,
0, 512, 768, 1024, 1536, 2048, 0, 0
};
/* Table 8 from ISO 7816-3:2006 */
-const uint8_t di_table[] = {
+const uint8_t iso7816_3_di_table[] = {
0, 1, 2, 4, 8, 16, 32, 64,
12, 20, 2, 4, 8, 16, 32, 64,
};
/* compute the F/D ratio based on Fi and Di values */
-int compute_fidi_ratio(uint8_t fi, uint8_t di)
+int iso7816_3_compute_fd_ratio(uint8_t f_index, uint8_t d_index)
{
uint16_t f, d;
int ret;
- if (fi >= ARRAY_SIZE(fi_table) ||
- di >= ARRAY_SIZE(di_table))
+ if (f_index >= ARRAY_SIZE(iso7816_3_fi_table) ||
+ d_index >= ARRAY_SIZE(iso7816_3_di_table))
return -EINVAL;
- f = fi_table[fi];
+ f = iso7816_3_fi_table[f_index];
if (f == 0)
return -EINVAL;
- d = di_table[di];
+ d = iso7816_3_di_table[d_index];
if (d == 0)
return -EINVAL;
/* See table 7 of ISO 7816-3: From 1000 on we divide by 1/d,
* which equals a multiplication by d */
- if (di < 8)
+ if (d_index < 8)
ret = f / d;
else
ret = f * d;
diff --git a/firmware/libcommon/source/simtrace_iso7816.c b/firmware/libcommon/source/simtrace_iso7816.c
index 8742696..27677a6 100644
--- a/firmware/libcommon/source/simtrace_iso7816.c
+++ b/firmware/libcommon/source/simtrace_iso7816.c
@@ -125,7 +125,7 @@ void update_fidi(Usart_info *usart, uint8_t fidi)
uint8_t fi = fidi >> 4;
uint8_t di = fidi & 0xf;
- int ratio = compute_fidi_ratio(fi, di);
+ int ratio = iso7816_3_compute_fd_ratio(fi, di);
if (ratio > 0 && ratio < 0x8000) {
/* make sure USART uses new F/D ratio */
diff --git a/firmware/libcommon/source/sniffer.c b/firmware/libcommon/source/sniffer.c
index 08770e2..57e2daa 100644
--- a/firmware/libcommon/source/sniffer.c
+++ b/firmware/libcommon/source/sniffer.c
@@ -658,9 +658,10 @@ static void process_byte_pps(uint8_t byte)
fn = 1;
dn = 1;
}
- TRACE_INFO("PPS negotiation successful: Fn=%u Dn=%u\n\r", fi_table[fn], di_table[dn]);
+ TRACE_INFO("PPS negotiation successful: Fn=%u Dn=%u\n\r",
+ iso7816_3_fi_table[fn], iso7816_3_di_table[dn]);
update_fidi(&sniff_usart, pps_cur[2]);
- update_wt(0, di_table[dn]);
+ update_wt(0, iso7816_3_di_table[dn]);
usb_send_fidi(pps_cur[2]); /* send Fi/Di change notification to host software over USB */
} else { /* checksum is invalid */
TRACE_INFO("PPS negotiation failed\n\r");