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;
131 MfClassicKeyType requested_key_type;
133 uint16_t current_block;
134 uint8_t reuse_key_sector;
135 MfClassicBackdoor backdoor;
136 MfClassicPollerMode mode;
139 MfClassicNestedPhase nested_phase;
141 MfClassicKeyType nested_known_key_type;
142 bool current_key_checked;
143 uint8_t nested_known_key_sector;
144 uint16_t nested_target_key;
146 MfClassicPrngType prng_type;
147 bool static_encrypted;
148 uint32_t static_encrypted_nonce;
152 uint8_t attempt_count;
158 uint16_t msb_par_sum;
163 uint8_t current_sector;
164 uint16_t current_block;
165 MfClassicKeyType key_type;
180 MfClassicPollerState state;
181 MfClassicAuthState auth_state;
182 MfClassicCardState card_state;
184 MfClassicType current_type_check;
185 uint8_t sectors_total;
186 MfClassicPollerMode mode;
205 MfClassicKeyType key_type;
212 MfClassicKeyType key_type;
219 MfClassicKeyType key_type;
226 MfClassicKeyType key_type;
233 MfClassicKeyType key_type;
234 MfClassicValueCommand value_cmd;
241 uint8_t current_sector;
254MfClassicError 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:230
Definition mf_classic_poller_i.h:203
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:202
Definition mf_classic_poller_i.h:177
Definition mf_classic_poller_i.h:162
Definition mf_classic_poller_i.h:116
Definition mf_classic_poller_i.h:209
Definition mf_classic_poller_i.h:239
Definition mf_classic_poller_i.h:223
Definition mf_classic_poller_i.h:216
Generic Nfc event type.
Definition nfc_generic_event.h:58
Definition mf_classic_poller_i.h:244
MfClassic poller event data.
Definition mf_classic_poller.h:184
Definition mf_classic_poller_i.h:170
Definition mf_classic.h:121