Change in simtrace2[master]: iso7816_fidi: Add iso7816_3_ prefix to symbols; fix terminology

2021-04-08 Thread laforge
laforge has submitted this change. ( 
https://gerrit.osmocom.org/c/simtrace2/+/23640 )

Change subject: iso7816_fidi: Add iso7816_3_ prefix to symbols; fix terminology
..

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
---
M firmware/libcommon/include/iso7816_fidi.h
M firmware/libcommon/source/card_emu.c
M firmware/libcommon/source/iso7816_fidi.c
M firmware/libcommon/source/simtrace_iso7816.c
M firmware/libcommon/source/sniffer.c
5 files changed, 19 insertions(+), 18 deletions(-)

Approvals:
  laforge: Looks good to me, approved
  Jenkins Builder: Verified



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 

 /* 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 @@
 {
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 @@
}
}
/* 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 @@
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 @@

uint8_t fi = fidi >> 4;
uint8_t di = fidi & 0xf;
-   int ratio = compute_fidi_ratio(fi, di);
+   

Change in simtrace2[master]: iso7816_fidi: Add iso7816_3_ prefix to symbols; fix terminology

2021-04-06 Thread laforge
laforge has posted comments on this change. ( 
https://gerrit.osmocom.org/c/simtrace2/+/23640 )

Change subject: iso7816_fidi: Add iso7816_3_ prefix to symbols; fix terminology
..


Patch Set 2: Code-Review+2


--
To view, visit https://gerrit.osmocom.org/c/simtrace2/+/23640
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: simtrace2
Gerrit-Branch: master
Gerrit-Change-Id: If364e08e7c9a3a9707e6d54b9267c6a7c088e415
Gerrit-Change-Number: 23640
Gerrit-PatchSet: 2
Gerrit-Owner: laforge 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge 
Gerrit-Comment-Date: Tue, 06 Apr 2021 15:51:21 +
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment


Change in simtrace2[master]: iso7816_fidi: Add iso7816_3_ prefix to symbols; fix terminology

2021-04-06 Thread laforge
Hello Jenkins Builder,

I'd like you to reexamine a change. Please visit

https://gerrit.osmocom.org/c/simtrace2/+/23640

to look at the new patch set (#2).

Change subject: iso7816_fidi: Add iso7816_3_ prefix to symbols; fix terminology
..

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
---
M firmware/libcommon/include/iso7816_fidi.h
M firmware/libcommon/source/card_emu.c
M firmware/libcommon/source/iso7816_fidi.c
M firmware/libcommon/source/simtrace_iso7816.c
M firmware/libcommon/source/sniffer.c
5 files changed, 19 insertions(+), 18 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/simtrace2 refs/changes/40/23640/2
--
To view, visit https://gerrit.osmocom.org/c/simtrace2/+/23640
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: simtrace2
Gerrit-Branch: master
Gerrit-Change-Id: If364e08e7c9a3a9707e6d54b9267c6a7c088e415
Gerrit-Change-Number: 23640
Gerrit-PatchSet: 2
Gerrit-Owner: laforge 
Gerrit-Reviewer: Jenkins Builder
Gerrit-MessageType: newpatchset


Change in simtrace2[master]: iso7816_fidi: Add iso7816_3_ prefix to symbols; fix terminology

2021-04-05 Thread laforge
laforge has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/simtrace2/+/23640 )


Change subject: iso7816_fidi: Add iso7816_3_ prefix to symbols; fix terminology
..

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
---
M firmware/libcommon/include/iso7816_fidi.h
M firmware/libcommon/source/card_emu.c
M firmware/libcommon/source/iso7816_fidi.c
M firmware/libcommon/source/simtrace_iso7816.c
M firmware/libcommon/source/sniffer.c
5 files changed, 19 insertions(+), 18 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/simtrace2 refs/changes/40/23640/1

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 

 /* 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 @@
 {
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 @@
}
}
/* 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 @@
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 @@

uint8_t fi = fidi >> 4;
uint8_t di = fidi & 0xf;
-   int ratio = compute_fidi_ratio(fi,