Kévin Redon | 4a29f64 | 2019-05-14 21:50:39 +0200 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2019 sysmocom -s.f.m.c. GmbH, Author: Kevin Redon <kredon@sysmocom.de> |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; either version 2 |
| 7 | * of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | */ |
| 18 | |
| 19 | /* this library provides utilities to handle the ISO-7816 part 3 communication aspects (e.g. related |
| 20 | * to F and D) */ |
| 21 | |
| 22 | #pragma once |
| 23 | |
| 24 | #include <stdint.h> |
| 25 | #include <stdbool.h> |
| 26 | |
| 27 | /*! default clock rate conversion integer Fd. |
| 28 | * ISO/IEC 7816-3:2006(E) section 8.1 */ |
| 29 | #define ISO7816_3_DEFAULT_FD 372 |
| 30 | |
| 31 | /*! default baud rate adjustment factor Dd. |
| 32 | * ISO/IEC 7816-3:2006(E) section 8.1 */ |
| 33 | #define ISO7816_3_DEFAULT_DD 1 |
| 34 | |
| 35 | /*! default clock rate conversion integer Fi. |
| 36 | * ISO/IEC 7816-3:2006(E) section 8.3 |
| 37 | * \note non-default value is optionally specified in TA1 */ |
| 38 | #define ISO7816_3_DEFAULT_FI 372 |
| 39 | |
| 40 | /*! default baud rate adjustment factor Di. |
| 41 | * ISO/IEC 7816-3:2006(E) section 8.3 |
| 42 | * \note non-default value is optionally specified in TA1 */ |
| 43 | #define ISO7816_3_DEFAULT_DI 1 |
| 44 | |
| 45 | /*! default maximum clock frequency, in Hz. |
| 46 | * ISO/IEC 7816-3:2006(E) section 8.3 |
| 47 | * \note non-default value is optionally specified in TA1 */ |
| 48 | #define ISO7816_3_DEFAULT_FMAX 5000000UL |
| 49 | |
| 50 | /*! default Waiting Integer (WI) value for T=0. |
| 51 | * ISO/IEC 7816-3:2006(E) section 10.2 |
| 52 | * \note non-default value is optionally specified in TC2 */ |
| 53 | #define ISO7816_3_DEFAULT_WI 10 |
| 54 | |
| 55 | /*! default Waiting Time (WT) value, in ETU. |
| 56 | * ISO/IEC 7816-3:2006(E) section 8.1 |
| 57 | * \note depends on Fi, Di, and WI if protocol T=0 is selected */ |
| 58 | #define ISO7816_3_DEFAULT_WT 9600 |
| 59 | |
| 60 | extern const uint16_t iso7816_3_fi_table[]; |
| 61 | |
| 62 | extern const uint32_t iso7816_3_fmax_table[]; |
| 63 | |
| 64 | extern const uint8_t iso7816_3_di_table[]; |
| 65 | |
| 66 | bool iso7816_3_valid_f(uint16_t f); |
| 67 | |
| 68 | bool iso7816_3_valid_d(uint8_t d); |
| 69 | |
| 70 | int32_t iso7816_3_calculate_wt(uint8_t wi, uint16_t fi, uint8_t di, uint16_t f, uint8_t d); |