mirror of
https://gitea.osmocom.org/sim-card/simtrace2.git
synced 2026-03-19 23:08:34 +03:00
Move Fi/Di calculation functions to separate C file
This commit is contained in:
@@ -32,6 +32,7 @@
|
||||
*------------------------------------------------------------------------------*/
|
||||
|
||||
#include "board.h"
|
||||
#include "iso7816_fidi.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
@@ -109,46 +110,6 @@ void USART1_IrqHandler( void )
|
||||
}
|
||||
|
||||
/* FIDI update functions */
|
||||
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
|
||||
|
||||
/* Table 6 from ISO 7816-3 */
|
||||
static const uint16_t fi_table[] = {
|
||||
0, 372, 558, 744, 1116, 1488, 1860, 0,
|
||||
0, 512, 768, 1024, 1536, 2048, 0, 0
|
||||
};
|
||||
|
||||
/* Table 7 from ISO 7816-3 */
|
||||
static const uint8_t di_table[] = {
|
||||
0, 1, 2, 4, 8, 16, 0, 0,
|
||||
0, 0, 2, 4, 8, 16, 32, 64,
|
||||
};
|
||||
|
||||
/* compute the F/D ratio based on Fi and Di values */
|
||||
static int compute_fidi_ratio(uint8_t fi, uint8_t di)
|
||||
{
|
||||
uint16_t f, d;
|
||||
int ret;
|
||||
|
||||
if (fi >= ARRAY_SIZE(fi_table) ||
|
||||
di >= ARRAY_SIZE(di_table))
|
||||
return -EINVAL;
|
||||
|
||||
f = fi_table[fi];
|
||||
if (f == 0)
|
||||
return -EINVAL;
|
||||
|
||||
d = di_table[di];
|
||||
if (d == 0)
|
||||
return -EINVAL;
|
||||
|
||||
if (di < 8)
|
||||
ret = f / d;
|
||||
else
|
||||
ret = f * d;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void update_fidi(uint8_t fidi)
|
||||
{
|
||||
int rc;
|
||||
|
||||
Reference in New Issue
Block a user