Loading...
Searching...
No Matches
mf_ultralight_listener_i.h
1#pragma once
2
3#include "mf_ultralight_listener.h"
4#include <lib/nfc/protocols/iso14443_3a/iso14443_3a_listener.h>
6
7#ifdef __cplusplus
8extern "C" {
9#endif
10
11typedef enum {
12 MfUltralightListenerAuthStateIdle,
13 MfUltralightListenerAuthStateSuccess,
14} MfUltralightListenerAuthState;
15
16typedef enum {
17 MfUltralightListenerAccessTypeRead,
18 MfUltralightListenerAccessTypeWrite,
19} MfUltralightListenerAccessType;
20
21typedef enum {
22 MfUltralightCommandNotFound,
23 MfUltralightCommandProcessed,
24 MfUltralightCommandProcessedACK,
25 MfUltralightCommandProcessedSilent,
26 MfUltralightCommandNotProcessedNAK,
27 MfUltralightCommandNotProcessedSilent,
28 MfUltralightCommandNotProcessedAuthNAK,
29} MfUltralightCommand;
30
31typedef MfUltralightCommand (
32 *MfUltralightListenerCommandCallback)(MfUltralightListener* instance, BitBuffer* buf);
33
34typedef uint8_t MfUltralightListenerCompositeCommandData;
35
36typedef struct {
37 MfUltralightListenerCompositeCommandData data;
38 MfUltralightListenerCommandCallback callback;
40
41typedef struct {
42 uint8_t enabled;
43 uint8_t ascii_offset;
44 uint8_t ascii_end;
45 uint8_t mirror_last_page;
46 MfUltralightMirrorConf actual_mode;
47 FuriString* ascii_mirror_data;
49
50typedef uint16_t MfUltralightStaticLockData;
51typedef uint32_t MfUltralightDynamicLockData;
52
54 Iso14443_3aListener* iso14443_3a_listener;
55 MfUltralightListenerAuthState auth_state;
56 MfUltralightData* data;
57 BitBuffer* tx_buffer;
58 MfUltralightFeatureSupport features;
60 MfUltralightStaticLockData* static_lock;
61 MfUltralightDynamicLockData* dynamic_lock;
62
63 NfcGenericEvent generic_event;
65 MfUltralightListenerEventData mfu_event_data;
66 NfcGenericCallback callback;
67 uint8_t sector;
68 bool single_counter_increased;
71 mbedtls_des3_context des_context;
72 uint8_t rndB[MF_ULTRALIGHT_C_AUTH_RND_BLOCK_SIZE];
73 uint8_t encB[MF_ULTRALIGHT_C_AUTH_RND_BLOCK_SIZE];
74 void* context;
75};
76
77void mf_ultralight_single_counter_try_increase(MfUltralightListener* instance);
78void mf_ultralight_single_counter_try_to_unlock(
79 MfUltralightListener* instance,
80 Iso14443_3aListenerEventType type);
81
82void mf_ultralight_mirror_prepare_emulation(MfUltralightListener* instance);
83void mf_ultraligt_mirror_format_counter(MfUltralightListener* instance);
84void mf_ultralight_mirror_read_prepare(uint8_t start_page, MfUltralightListener* instance);
85void mf_ultralight_mirror_read_handler(
86 uint8_t mirror_page_num,
87 uint8_t* dest,
88 MfUltralightListener* instance);
89
90void mf_ultralight_composite_command_set_next(
91 MfUltralightListener* instance,
92 const MfUltralightListenerCommandCallback handler);
93void mf_ultralight_composite_command_reset(MfUltralightListener* instance);
94bool mf_ultralight_composite_command_in_progress(MfUltralightListener* instance);
95MfUltralightCommand
96 mf_ultralight_composite_command_run(MfUltralightListener* instance, BitBuffer* buffer);
97
98bool mf_ultralight_is_i2c_tag(MfUltralightType type);
99bool mf_ultralight_i2c_validate_pages(
100 uint16_t start_page,
101 uint16_t end_page,
102 MfUltralightListener* instance);
103
104uint16_t
105 mf_ultralight_i2c_provide_page_by_requested(uint16_t page, MfUltralightListener* instance);
106
107void mf_ultralight_static_lock_bytes_prepare(MfUltralightListener* instance);
108void mf_ultralight_static_lock_bytes_write(
109 MfUltralightStaticLockData* const lock_bits,
110 uint16_t new_bits);
111bool mf_ultralight_static_lock_check_page(
112 const MfUltralightStaticLockData* const lock_bits,
113 uint16_t page);
114
115void mf_ultralight_capability_container_write(
116 MfUltralightPage* const current_page,
117 const uint8_t* const new_data);
118
119void mf_ultralight_dynamic_lock_bytes_prepare(MfUltralightListener* instance);
120bool mf_ultralight_is_page_dynamic_lock(const MfUltralightListener* instance, uint16_t start_page);
121void mf_ultralight_dynamic_lock_bytes_write(
122 MfUltralightDynamicLockData* const lock_bits,
123 uint32_t new_bits);
124bool mf_ultralight_dynamic_lock_check_page(const MfUltralightListener* instance, uint16_t page);
125bool mf_ultralight_auth_limit_check_and_update(MfUltralightListener* instance, bool auth_success);
126bool mf_ultralight_auth_check_password(
127 const MfUltralightAuthPassword* config_pass,
128 const MfUltralightAuthPassword* auth_pass);
129
130bool mf_ultralight_common_check_access(
131 const MfUltralightListener* instance,
132 const uint16_t start_page,
133 const MfUltralightListenerAccessType access_type);
134
135bool mf_ultralight_c_check_access(
136 const MfUltralightData* data,
137 const uint16_t start_page,
138 const MfUltralightListenerAccessType access_type,
139 const MfUltralightListenerAuthState auth_state);
140#ifdef __cplusplus
141}
142#endif
Generic Nfc stack event definitions.
NfcCommand(* NfcGenericCallback)(NfcGenericEvent event, void *context)
Generic Nfc event callback type.
Definition nfc_generic_event.h:75
Definition bit_buffer.c:7
Definition hid_profile.c:33
Definition string.c:4
Definition iso14443_3a_listener_i.h:15
Definition mf_ultralight.h:127
Definition mf_ultralight.h:178
Definition mf_ultralight_listener_i.h:36
Definition mf_ultralight_listener.h:15
Definition mf_ultralight_listener.h:21
Definition mf_ultralight_listener_i.h:53
Definition mf_ultralight_listener_i.h:41
Definition mf_ultralight.h:95
Generic Nfc event type.
Definition nfc_generic_event.h:58