Flipper Zero Firmware
Loading...
Searching...
No Matches
mf_classic_poller_i.h
1#pragma once
2
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/crypto1.h>
7
8#ifdef __cplusplus
9extern "C" {
10#endif
11
12#define MF_CLASSIC_FWT_FC (60000)
13
14typedef enum {
15 MfClassicAuthStateIdle,
16 MfClassicAuthStatePassed,
17} MfClassicAuthState;
18
19typedef enum {
20 MfClassicCardStateDetected,
21 MfClassicCardStateLost,
22} MfClassicCardState;
23
24typedef enum {
25 MfClassicPollerStateDetectType,
26 MfClassicPollerStateStart,
27
28 // Write states
29 MfClassicPollerStateRequestSectorTrailer,
30 MfClassicPollerStateCheckWriteConditions,
31 MfClassicPollerStateReadBlock,
32 MfClassicPollerStateWriteBlock,
33 MfClassicPollerStateWriteValueBlock,
34
35 // Read states
36 MfClassicPollerStateRequestReadSector,
37 MfClassicPollerStateReadSectorBlocks,
38
39 // Dict attack states
40 MfClassicPollerStateNextSector,
41 MfClassicPollerStateRequestKey,
42 MfClassicPollerStateReadSector,
43 MfClassicPollerStateAuthKeyA,
44 MfClassicPollerStateAuthKeyB,
45 MfClassicPollerStateKeyReuseStart,
46 MfClassicPollerStateKeyReuseAuthKeyA,
47 MfClassicPollerStateKeyReuseAuthKeyB,
48 MfClassicPollerStateKeyReuseReadSector,
49 MfClassicPollerStateSuccess,
50 MfClassicPollerStateFail,
51
52 MfClassicPollerStateNum,
53} MfClassicPollerState;
54
55typedef struct {
56 uint8_t current_sector;
58 uint16_t current_block;
59 bool is_value_block;
60 MfClassicKeyType key_type_read;
61 MfClassicKeyType key_type_write;
62 bool need_halt_before_write;
63 MfClassicBlock tag_block;
65
66typedef struct {
67 uint8_t current_sector;
68 MfClassicKey current_key;
69 MfClassicKeyType current_key_type;
70 bool auth_passed;
71 uint16_t current_block;
72 uint8_t reuse_key_sector;
74
75typedef struct {
76 uint8_t current_sector;
77 uint16_t current_block;
78 MfClassicKeyType key_type;
79 MfClassicKey key;
80 bool auth_passed;
82
89
91 Iso14443_3aPoller* iso14443_3a_poller;
92
93 MfClassicPollerState state;
94 MfClassicAuthState auth_state;
95 MfClassicCardState card_state;
96
97 MfClassicType current_type_check;
98 uint8_t sectors_total;
100
101 Crypto1* crypto;
102 BitBuffer* tx_plain_buffer;
103 BitBuffer* tx_encrypted_buffer;
104 BitBuffer* rx_plain_buffer;
105 BitBuffer* rx_encrypted_buffer;
106 MfClassicData* data;
107
108 NfcGenericEvent general_event;
109 MfClassicPollerEvent mfc_event;
110 MfClassicPollerEventData mfc_event_data;
111 NfcGenericCallback callback;
112 void* context;
113};
114
115typedef struct {
116 uint8_t block;
117 MfClassicKeyType key_type;
118 MfClassicNt nt;
120
121typedef struct {
122 uint8_t block_num;
123 MfClassicKey key;
124 MfClassicKeyType key_type;
125 MfClassicBlock block;
127
128typedef struct {
129 uint8_t block_num;
130 MfClassicKey key;
131 MfClassicKeyType key_type;
132 MfClassicBlock block;
134
135typedef struct {
136 uint8_t block_num;
137 MfClassicKey key;
138 MfClassicKeyType key_type;
139 int32_t value;
141
142typedef struct {
143 uint8_t block_num;
144 MfClassicKey key;
145 MfClassicKeyType key_type;
146 MfClassicValueCommand value_cmd;
147 int32_t data;
148 int32_t new_value;
150
151typedef struct {
153 uint8_t current_sector;
155
156typedef union {
157 MfClassicCollectNtContext collect_nt_context;
158 MfClassicAuthContext auth_context;
159 MfClassicReadBlockContext read_block_context;
160 MfClassicWriteBlockContext write_block_context;
161 MfClassicReadValueContext read_value_context;
162 MfClassicChangeValueContext change_value_context;
163 MfClassicReadContext read_context;
165
166MfClassicError mf_classic_process_error(Iso14443_3aError error);
167
168MfClassicPoller* mf_classic_poller_alloc(Iso14443_3aPoller* iso14443_3a_poller);
169
170void mf_classic_poller_free(MfClassicPoller* instance);
171
172#ifdef __cplusplus
173}
174#endif
NfcCommand(* NfcGenericCallback)(NfcGenericEvent event, void *context)
Generic Nfc event callback type.
Definition nfc_generic_event.h:75
Definition bit_buffer.c:7
Definition crypto1.h:9
Definition iso14443_3a_poller_i.h:42
Definition mf_classic.h:109
Definition mf_classic.h:76
Definition mf_classic_poller_i.h:142
Definition mf_classic_poller_i.h:115
Definition mf_classic.h:135
Definition mf_classic.h:128
Definition mf_classic.h:85
Definition mf_classic.h:93
Definition mf_classic_poller_i.h:66
MfClassic poller event.
Definition mf_classic_poller.h:157
Definition mf_classic_poller_i.h:90
Definition mf_classic_poller_i.h:75
Definition mf_classic_poller_i.h:55
Definition mf_classic_poller_i.h:121
Definition mf_classic_poller_i.h:151
Definition mf_classic_poller_i.h:135
Definition mf_classic_poller_i.h:128
Generic Nfc event type.
Definition nfc_generic_event.h:58
Definition mf_classic_poller_i.h:156
MfClassic poller event data.
Definition mf_classic_poller.h:139
Definition mf_classic_poller_i.h:83
Definition mf_classic.h:119