3#include "mf_classic_poller.h"
4#include <lib/nfc/protocols/iso14443_3a/iso14443_3a_poller_i.h>
5#include <bit_lib/bit_lib.h>
6#include <nfc/helpers/iso14443_crc.h>
7#include <nfc/helpers/crypto1.h>
8#include <stream/stream.h>
9#include <stream/buffered_file_stream.h>
10#include <toolbox/keys_dict.h>
11#include <helpers/nfc_util.h>
17#define MF_CLASSIC_FWT_FC (60000)
18#define NFC_FOLDER EXT_PATH("nfc")
19#define NFC_ASSETS_FOLDER EXT_PATH("nfc/assets")
20#define MF_CLASSIC_NESTED_ANALYZE_NT_COUNT (5)
21#define MF_CLASSIC_NESTED_NT_HARD_MINIMUM (3)
22#define MF_CLASSIC_NESTED_RETRY_MAXIMUM (60)
23#define MF_CLASSIC_NESTED_HARD_RETRY_MAXIMUM (3)
24#define MF_CLASSIC_NESTED_CALIBRATION_COUNT (21)
25#define MF_CLASSIC_NESTED_LOGS_FILE_NAME ".nested.log"
26#define MF_CLASSIC_NESTED_SYSTEM_DICT_FILE_NAME "mf_classic_dict_nested.nfc"
27#define MF_CLASSIC_NESTED_USER_DICT_FILE_NAME "mf_classic_dict_user_nested.nfc"
28#define MF_CLASSIC_NESTED_LOGS_FILE_PATH (NFC_FOLDER "/" MF_CLASSIC_NESTED_LOGS_FILE_NAME)
29#define MF_CLASSIC_NESTED_SYSTEM_DICT_PATH \
30 (NFC_ASSETS_FOLDER "/" MF_CLASSIC_NESTED_SYSTEM_DICT_FILE_NAME)
31#define MF_CLASSIC_NESTED_USER_DICT_PATH \
32 (NFC_ASSETS_FOLDER "/" MF_CLASSIC_NESTED_USER_DICT_FILE_NAME)
33#define SET_PACKED_BIT(arr, bit) ((arr)[(bit) / 8] |= (1 << ((bit) % 8)))
34#define GET_PACKED_BIT(arr, bit) ((arr)[(bit) / 8] & (1 << ((bit) % 8)))
39extern const uint16_t valid_sums[19];
42 MfClassicAuthStateIdle,
43 MfClassicAuthStatePassed,
47 MfClassicCardStateDetected,
48 MfClassicCardStateLost,
53 MfClassicBackdoor type;
57extern const size_t mf_classic_backdoor_keys_count;
74 MfClassicPollerStateDetectType,
75 MfClassicPollerStateStart,
78 MfClassicPollerStateRequestSectorTrailer,
79 MfClassicPollerStateCheckWriteConditions,
80 MfClassicPollerStateReadBlock,
81 MfClassicPollerStateWriteBlock,
82 MfClassicPollerStateWriteValueBlock,
85 MfClassicPollerStateRequestReadSector,
86 MfClassicPollerStateReadSectorBlocks,
89 MfClassicPollerStateNextSector,
90 MfClassicPollerStateAnalyzeBackdoor,
91 MfClassicPollerStateBackdoorReadSector,
92 MfClassicPollerStateRequestKey,
93 MfClassicPollerStateReadSector,
94 MfClassicPollerStateAuthKeyA,
95 MfClassicPollerStateAuthKeyB,
96 MfClassicPollerStateKeyReuseStart,
97 MfClassicPollerStateKeyReuseStartNoOffset,
98 MfClassicPollerStateKeyReuseAuthKeyA,
99 MfClassicPollerStateKeyReuseAuthKeyB,
100 MfClassicPollerStateKeyReuseReadSector,
101 MfClassicPollerStateSuccess,
102 MfClassicPollerStateFail,
105 MfClassicPollerStateNestedAnalyzePRNG,
106 MfClassicPollerStateNestedCalibrate,
107 MfClassicPollerStateNestedCollectNt,
108 MfClassicPollerStateNestedController,
109 MfClassicPollerStateNestedCollectNtEnc,
110 MfClassicPollerStateNestedDictAttack,
111 MfClassicPollerStateNestedLog,
113 MfClassicPollerStateNum,
114} MfClassicPollerState;
117 uint8_t current_sector;
119 uint16_t current_block;
121 MfClassicKeyType key_type_read;
122 MfClassicKeyType key_type_write;
123 bool need_halt_before_write;
128 uint8_t current_sector;
130 MfClassicKeyType current_key_type;
132 uint16_t current_block;
133 uint8_t reuse_key_sector;
134 MfClassicBackdoor backdoor;
137 MfClassicNestedPhase nested_phase;
139 MfClassicKeyType nested_known_key_type;
140 bool current_key_checked;
141 uint8_t nested_known_key_sector;
142 uint16_t nested_target_key;
144 MfClassicPrngType prng_type;
145 bool static_encrypted;
146 uint32_t static_encrypted_nonce;
150 uint8_t attempt_count;
156 uint16_t msb_par_sum;
161 uint8_t current_sector;
162 uint16_t current_block;
163 MfClassicKeyType key_type;
178 MfClassicPollerState state;
179 MfClassicAuthState auth_state;
180 MfClassicCardState card_state;
182 MfClassicType current_type_check;
183 uint8_t sectors_total;
202 MfClassicKeyType key_type;
209 MfClassicKeyType key_type;
216 MfClassicKeyType key_type;
223 MfClassicKeyType key_type;
230 MfClassicKeyType key_type;
231 MfClassicValueCommand value_cmd;
238 uint8_t current_sector;
251MfClassicError mf_classic_process_error(Iso14443_3aError error);
NfcCommand(* NfcGenericCallback)(NfcGenericEvent event, void *context)
Generic Nfc event callback type.
Definition nfc_generic_event.h:75
Definition bit_buffer.c:7
Definition iso14443_3a_poller_i.h:42
Definition keys_dict.c:11
Definition mf_classic.h:111
Definition mf_classic_poller_i.h:51
Definition mf_classic.h:78
Definition mf_classic_poller_i.h:227
Definition mf_classic_poller_i.h:200
Definition mf_classic.h:137
Definition mf_classic.h:130
Definition mf_classic.h:87
Definition mf_classic_poller_i.h:68
Definition mf_classic_poller_i.h:59
Definition mf_classic.h:95
Definition mf_classic_poller_i.h:127
MfClassic poller event.
Definition mf_classic_poller.h:200
Definition mf_classic_poller_i.h:175
Definition mf_classic_poller_i.h:160
Definition mf_classic_poller_i.h:116
Definition mf_classic_poller_i.h:206
Definition mf_classic_poller_i.h:236
Definition mf_classic_poller_i.h:220
Definition mf_classic_poller_i.h:213
Generic Nfc event type.
Definition nfc_generic_event.h:58
Definition mf_classic_poller_i.h:241
MfClassic poller event data.
Definition mf_classic_poller.h:182
Definition mf_classic_poller_i.h:168
Definition mf_classic.h:121