Change in simtrace2[master]: card_emu: Clarify and differentiate F/Fi/F_index/Fi_index

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

Change subject: card_emu: Clarify and differentiate F/Fi/F_index/Fi_index
..

card_emu: Clarify and differentiate F/Fi/F_index/Fi_index

The ISO7816 spec terms are well-defined, let's not abuse them. We used
to consider "Fi" as the "index into the table of F values", while the
spec actually considers Fi as the initial value for F.

Let's make sure we use the terms quite clearly:
* Fi and Di are the initial values for F and D
* F*_index and D*_index are the indexes into the ISO7816-3 Tables

Furthermore, let's track Fi separately from F, as e.g. the waiting
time definition only considers Fi as indicated in the ATR, despite
an actually different F value might have been negotiated via PTS
meanwhile.

Change-Id: Ieb2425e8380a81b79df7b2bd072902994e9c3ee7
Related: OS##1704
---
M firmware/libcommon/include/simtrace_prot.h
M firmware/libcommon/source/card_emu.c
2 files changed, 52 insertions(+), 26 deletions(-)

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



diff --git a/firmware/libcommon/include/simtrace_prot.h 
b/firmware/libcommon/include/simtrace_prot.h
index eca844a..e550616 100644
--- a/firmware/libcommon/include/simtrace_prot.h
+++ b/firmware/libcommon/include/simtrace_prot.h
@@ -230,11 +230,17 @@
uint32_t flags;
/* phone-applied target voltage in mV */
uint16_t voltage_mv;
-   /* Fi/Di related information */
-   uint8_t fi;
-   uint8_t di;
-   uint8_t wi;
-   uint32_t waiting_time;
+   /* F/D related information. Not actual Fn/Dn values but indexes into 
tables! */
+   union {
+   uint8_t F_index;/* 
+ * (C) 2010-2021 by Harald Welte 
  * (C) 2018 by sysmocom -s.f.m.c. GmbH, Author: Kevin Redon 

  *
  * This program is free software; you can redistribute it and/or modify
@@ -154,19 +154,35 @@
bool in_reset;  /*< if card is in reset (true = RST low/asserted, false 
= RST high/ released) */
bool clocked;   /*< if clock is active ( true = active, false = 
inactive) */

-   /* timing parameters, from PTS */
-   uint8_t Fi;
-   uint8_t Di;
+   /* All below variables with _index suffix are indexes from 0..15 into 
Tables 7 + 8
+* of ISO7816-3. */
+
+   /*! Index to clock rate conversion integer Fi (ISO7816-3 Table 7).
+*  \note this represents the maximum value supported by the card, and 
can be indicated in TA1 */
+   uint8_t Fi_index;
+   /*! Current value of index to clock rate conversion integer F (ISO 
7816-3 Section 7.1). */
+   uint8_t F_index;
+
+   /*! Index to baud rate adjustment factor Di (ISO7816-3 Table 8).
+*  \note this represents the maximum value supported by the card, and 
can be indicated in TA1 */
+   uint8_t Di_index;
+   /*! Current value of index to baud rate adjustment factor D (ISO 7816-3 
Section 7.1). */
+   uint8_t D_index;
+
+   /*! Waiting Integer (ISO7816-3 Section 10.2).
+*  \note this value can be set in TA2 */
uint8_t wi;

+   /*! Waiting Time, in ETU (ISO7816-3 Section 8.1).
+*  \note this depends on Fi, Di, and WI if T=0 is used */
+   uint32_t waiting_time;  /* in etu */
+
uint8_t tc_chan;/* TC channel number */
uint8_t uart_chan;  /* UART channel */

uint8_t in_ep;  /* USB IN EP */
uint8_t irq_ep; /* USB IN EP */

-   uint32_t waiting_time;  /* in etu */
-
/* ATR state machine */
struct {
uint8_t idx;
@@ -361,16 +377,16 @@
 {
int rc;

-   rc = compute_fidi_ratio(ch->Fi, ch->Di);
+   rc = compute_fidi_ratio(ch->F_index, ch->D_index);
if (rc > 0 && rc < 0x400) {
-   TRACE_INFO("%u: computed Fi(%u) Di(%u) ratio: %d\r\n",
-   ch->num, ch->Fi, ch->Di, rc);
+   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 */
card_emu_uart_update_fidi(ch->uart_chan, rc);
/* notify ETU timer about this */
tc_etu_set_etu(ch->tc_chan, rc);
} else
-   TRACE_INFO("%u: computed FiDi ration %d unsupported\r\n",
+   TRACE_INFO("%u: computed F/D ratio %d unsupported\r\n",
   ch->num, rc);
 }

@@ -395,8 +411,10 @@
break;
case ISO_S_WAIT_ATR:
/* Reset to initial Fi / Di ratio */
-   ch->Fi = 1;
-   ch->Di = 1;
+   ch->Fi_index = ch->F_index = 1;
+   ch->Di_index = ch->D_index = 1;
+   ch->wi = ISO7816_3_DEFAULT_WI;
+   ch->waiting_time = ISO7816_3_INIT_WTIME;
emu_update_fidi(ch);
/* the ATR 

Change in simtrace2[master]: card_emu: Clarify and differentiate F/Fi/F_index/Fi_index

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

Change subject: card_emu: Clarify and differentiate F/Fi/F_index/Fi_index
..


Patch Set 2: Code-Review+2


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

Gerrit-Project: simtrace2
Gerrit-Branch: master
Gerrit-Change-Id: Ieb2425e8380a81b79df7b2bd072902994e9c3ee7
Gerrit-Change-Number: 23639
Gerrit-PatchSet: 2
Gerrit-Owner: laforge 
Gerrit-Reviewer: Hoernchen 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge 
Gerrit-Reviewer: tsaitgaist 
Gerrit-Comment-Date: Thu, 08 Apr 2021 21:28:08 +
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment


Change in simtrace2[master]: card_emu: Clarify and differentiate F/Fi/F_index/Fi_index

2021-04-06 Thread laforge
Hello Jenkins Builder,

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

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

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

Change subject: card_emu: Clarify and differentiate F/Fi/F_index/Fi_index
..

card_emu: Clarify and differentiate F/Fi/F_index/Fi_index

The ISO7816 spec terms are well-defined, let's not abuse them. We used
to consider "Fi" as the "index into the table of F values", while the
spec actually considers Fi as the initial value for F.

Let's make sure we use the terms quite clearly:
* Fi and Di are the initial values for F and D
* F*_index and D*_index are the indexes into the ISO7816-3 Tables

Furthermore, let's track Fi separately from F, as e.g. the waiting
time definition only considers Fi as indicated in the ATR, despite
an actually different F value might have been negotiated via PTS
meanwhile.

Change-Id: Ieb2425e8380a81b79df7b2bd072902994e9c3ee7
Related: OS##1704
---
M firmware/libcommon/include/simtrace_prot.h
M firmware/libcommon/source/card_emu.c
2 files changed, 52 insertions(+), 26 deletions(-)


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

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


Change in simtrace2[master]: card_emu: Clarify and differentiate F/Fi/F_index/Fi_index

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


Change subject: card_emu: Clarify and differentiate F/Fi/F_index/Fi_index
..

card_emu: Clarify and differentiate F/Fi/F_index/Fi_index

The ISO7816 spec terms are well-defined, let's not abuse them. We used
to consider "Fi" as the "index into the table of F values", while the
spec actually considers Fi as the initial value for F.

Let's make sure we use the terms quite clearly:
* Fi and Di are the initial values for F and D
* F*_index and D*_index are the indexes into the ISO7816-3 Tables

Furthermore, let's track Fi separately from F, as e.g. the waiting
time definition only considers Fi as indicated in the ATR, despite
an actually different F value might have been negotiated via PTS
meanwhile.

Change-Id: Ieb2425e8380a81b79df7b2bd072902994e9c3ee7
---
M firmware/libcommon/include/simtrace_prot.h
M firmware/libcommon/source/card_emu.c
2 files changed, 52 insertions(+), 26 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/simtrace2 refs/changes/39/23639/1

diff --git a/firmware/libcommon/include/simtrace_prot.h 
b/firmware/libcommon/include/simtrace_prot.h
index eca844a..e550616 100644
--- a/firmware/libcommon/include/simtrace_prot.h
+++ b/firmware/libcommon/include/simtrace_prot.h
@@ -230,11 +230,17 @@
uint32_t flags;
/* phone-applied target voltage in mV */
uint16_t voltage_mv;
-   /* Fi/Di related information */
-   uint8_t fi;
-   uint8_t di;
-   uint8_t wi;
-   uint32_t waiting_time;
+   /* F/D related information. Not actual Fn/Dn values but indexes into 
tables! */
+   union {
+   uint8_t F_index;/* 
+ * (C) 2010-2021 by Harald Welte 
  * (C) 2018 by sysmocom -s.f.m.c. GmbH, Author: Kevin Redon 

  *
  * This program is free software; you can redistribute it and/or modify
@@ -154,19 +154,35 @@
bool in_reset;  /*< if card is in reset (true = RST low/asserted, false 
= RST high/ released) */
bool clocked;   /*< if clock is active ( true = active, false = 
inactive) */

-   /* timing parameters, from PTS */
-   uint8_t Fi;
-   uint8_t Di;
+   /* All below variables with _index suffix are indexes from 0..15 into 
Tables 7 + 8
+* of ISO7816-3. */
+
+   /*! Index to clock rate conversion integer Fi (ISO7816-3 Table 7).
+*  \note this represents the maximum value supported by the card, and 
can be indicated in TA1 */
+   uint8_t Fi_index;
+   /*! Current value of index to clock rate conversion integer F (ISO 
7816-3 Section 7.1). */
+   uint8_t F_index;
+
+   /*! Index to baud rate adjustment factor Di (ISO7816-3 Table 8).
+*  \note this represents the maximum value supported by the card, and 
can be indicated in TA1 */
+   uint8_t Di_index;
+   /*! Current value of index to baud rate adjustment factor D (ISO 7816-3 
Section 7.1). */
+   uint8_t D_index;
+
+   /*! Waiting Integer (ISO7816-3 Section 10.2).
+*  \note this value can be set in TA2 */
uint8_t wi;

+   /*! Waiting Time, in ETU (ISO7816-3 Section 8.1).
+*  \note this depends on Fi, Di, and WI if T=0 is used */
+   uint32_t waiting_time;  /* in etu */
+
uint8_t tc_chan;/* TC channel number */
uint8_t uart_chan;  /* UART channel */

uint8_t in_ep;  /* USB IN EP */
uint8_t irq_ep; /* USB IN EP */

-   uint32_t waiting_time;  /* in etu */
-
/* ATR state machine */
struct {
uint8_t idx;
@@ -361,16 +377,16 @@
 {
int rc;

-   rc = compute_fidi_ratio(ch->Fi, ch->Di);
+   rc = compute_fidi_ratio(ch->F_index, ch->D_index);
if (rc > 0 && rc < 0x400) {
-   TRACE_INFO("%u: computed Fi(%u) Di(%u) ratio: %d\r\n",
-   ch->num, ch->Fi, ch->Di, rc);
+   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 */
card_emu_uart_update_fidi(ch->uart_chan, rc);
/* notify ETU timer about this */
tc_etu_set_etu(ch->tc_chan, rc);
} else
-   TRACE_INFO("%u: computed FiDi ration %d unsupported\r\n",
+   TRACE_INFO("%u: computed F/D ratio %d unsupported\r\n",
   ch->num, rc);
 }

@@ -395,8 +411,10 @@
break;
case ISO_S_WAIT_ATR:
/* Reset to initial Fi / Di ratio */
-   ch->Fi = 1;
-   ch->Di = 1;
+   ch->Fi_index = ch->F_index = 1;
+   ch->Di_index = ch->D_index = 1;
+   ch->wi = ISO7816_3_DEFAULT_WI;
+   ch->waiting_time = ISO7816_3_INIT_WTIME;
emu_update_fidi(ch);
/* the ATR should only