mirror of
https://github.com/DarkFlippers/unleashed-firmware
synced 2024-11-10 15:04:19 +00:00
Merge branch 'fz-dev' into dev
This commit is contained in:
commit
e8e000d17b
11 changed files with 308 additions and 87 deletions
10
applications/debug/direct_draw/application.fam
Normal file
10
applications/debug/direct_draw/application.fam
Normal file
|
@ -0,0 +1,10 @@
|
|||
App(
|
||||
appid="direct_draw",
|
||||
name="Direct Draw",
|
||||
apptype=FlipperAppType.DEBUG,
|
||||
entry_point="direct_draw_app",
|
||||
requires=["gui", "input"],
|
||||
stack_size=2 * 1024,
|
||||
order=70,
|
||||
fap_category="Debug",
|
||||
)
|
112
applications/debug/direct_draw/direct_draw.c
Normal file
112
applications/debug/direct_draw/direct_draw.c
Normal file
|
@ -0,0 +1,112 @@
|
|||
#include <furi.h>
|
||||
#include <gui/gui.h>
|
||||
#include <gui/canvas_i.h>
|
||||
#include <input/input.h>
|
||||
|
||||
#define BUFFER_SIZE (32U)
|
||||
|
||||
typedef struct {
|
||||
FuriPubSub* input;
|
||||
FuriPubSubSubscription* input_subscription;
|
||||
Gui* gui;
|
||||
Canvas* canvas;
|
||||
bool stop;
|
||||
uint32_t counter;
|
||||
} DirectDraw;
|
||||
|
||||
static void gui_input_events_callback(const void* value, void* ctx) {
|
||||
furi_assert(value);
|
||||
furi_assert(ctx);
|
||||
|
||||
DirectDraw* instance = ctx;
|
||||
const InputEvent* event = value;
|
||||
|
||||
if(event->key == InputKeyBack && event->type == InputTypeShort) {
|
||||
instance->stop = true;
|
||||
}
|
||||
}
|
||||
|
||||
static DirectDraw* direct_draw_alloc() {
|
||||
DirectDraw* instance = malloc(sizeof(DirectDraw));
|
||||
|
||||
instance->input = furi_record_open(RECORD_INPUT_EVENTS);
|
||||
instance->gui = furi_record_open(RECORD_GUI);
|
||||
instance->canvas = gui_direct_draw_acquire(instance->gui);
|
||||
|
||||
instance->input_subscription =
|
||||
furi_pubsub_subscribe(instance->input, gui_input_events_callback, instance);
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
static void direct_draw_free(DirectDraw* instance) {
|
||||
furi_pubsub_unsubscribe(instance->input, instance->input_subscription);
|
||||
|
||||
instance->canvas = NULL;
|
||||
gui_direct_draw_release(instance->gui);
|
||||
furi_record_close(RECORD_GUI);
|
||||
furi_record_close(RECORD_INPUT_EVENTS);
|
||||
}
|
||||
|
||||
static void direct_draw_block(Canvas* canvas, uint32_t size, uint32_t counter) {
|
||||
size += 16;
|
||||
uint8_t width = canvas_width(canvas) - size;
|
||||
uint8_t height = canvas_height(canvas) - size;
|
||||
|
||||
uint8_t x = counter % width;
|
||||
if((counter / width) % 2) {
|
||||
x = width - x;
|
||||
}
|
||||
|
||||
uint8_t y = counter % height;
|
||||
if((counter / height) % 2) {
|
||||
y = height - y;
|
||||
}
|
||||
|
||||
canvas_draw_box(canvas, x, y, size, size);
|
||||
}
|
||||
|
||||
static void direct_draw_run(DirectDraw* instance) {
|
||||
size_t start = DWT->CYCCNT;
|
||||
size_t counter = 0;
|
||||
float fps = 0;
|
||||
|
||||
vTaskPrioritySet(furi_thread_get_current_id(), FuriThreadPriorityIdle);
|
||||
|
||||
do {
|
||||
size_t elapsed = DWT->CYCCNT - start;
|
||||
char buffer[BUFFER_SIZE] = {0};
|
||||
|
||||
if(elapsed >= 64000000) {
|
||||
fps = (float)counter / ((float)elapsed / 64000000.0f);
|
||||
|
||||
start = DWT->CYCCNT;
|
||||
counter = 0;
|
||||
}
|
||||
snprintf(buffer, BUFFER_SIZE, "FPS: %.1f", (double)fps);
|
||||
|
||||
canvas_reset(instance->canvas);
|
||||
canvas_set_color(instance->canvas, ColorXOR);
|
||||
direct_draw_block(instance->canvas, instance->counter % 16, instance->counter);
|
||||
direct_draw_block(instance->canvas, instance->counter * 2 % 16, instance->counter * 2);
|
||||
direct_draw_block(instance->canvas, instance->counter * 3 % 16, instance->counter * 3);
|
||||
direct_draw_block(instance->canvas, instance->counter * 4 % 16, instance->counter * 4);
|
||||
direct_draw_block(instance->canvas, instance->counter * 5 % 16, instance->counter * 5);
|
||||
canvas_draw_str(instance->canvas, 10, 10, buffer);
|
||||
canvas_commit(instance->canvas);
|
||||
|
||||
counter++;
|
||||
instance->counter++;
|
||||
furi_thread_yield();
|
||||
} while(!instance->stop);
|
||||
}
|
||||
|
||||
int32_t direct_draw_app(void* p) {
|
||||
UNUSED(p);
|
||||
|
||||
DirectDraw* instance = direct_draw_alloc();
|
||||
direct_draw_run(instance);
|
||||
direct_draw_free(instance);
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -68,6 +68,18 @@ typedef struct {
|
|||
/** Canvas anonymous structure */
|
||||
typedef struct Canvas Canvas;
|
||||
|
||||
/** Reset canvas drawing tools configuration
|
||||
*
|
||||
* @param canvas Canvas instance
|
||||
*/
|
||||
void canvas_reset(Canvas* canvas);
|
||||
|
||||
/** Commit canvas. Send buffer to display
|
||||
*
|
||||
* @param canvas Canvas instance
|
||||
*/
|
||||
void canvas_commit(Canvas* canvas);
|
||||
|
||||
/** Get Canvas width
|
||||
*
|
||||
* @param canvas Canvas instance
|
||||
|
|
|
@ -35,18 +35,6 @@ Canvas* canvas_init();
|
|||
*/
|
||||
void canvas_free(Canvas* canvas);
|
||||
|
||||
/** Reset canvas drawing tools configuration
|
||||
*
|
||||
* @param canvas Canvas instance
|
||||
*/
|
||||
void canvas_reset(Canvas* canvas);
|
||||
|
||||
/** Commit canvas. Send buffer to display
|
||||
*
|
||||
* @param canvas Canvas instance
|
||||
*/
|
||||
void canvas_commit(Canvas* canvas);
|
||||
|
||||
/** Get canvas buffer.
|
||||
*
|
||||
* @param canvas Canvas instance
|
||||
|
|
|
@ -20,7 +20,7 @@ ViewPort* gui_view_port_find_enabled(ViewPortArray_t array) {
|
|||
|
||||
void gui_update(Gui* gui) {
|
||||
furi_assert(gui);
|
||||
furi_thread_flags_set(gui->thread_id, GUI_THREAD_FLAG_DRAW);
|
||||
if(!gui->direct_draw) furi_thread_flags_set(gui->thread_id, GUI_THREAD_FLAG_DRAW);
|
||||
}
|
||||
|
||||
void gui_input_events_callback(const void* value, void* ctx) {
|
||||
|
@ -34,7 +34,7 @@ void gui_input_events_callback(const void* value, void* ctx) {
|
|||
}
|
||||
|
||||
// Only Fullscreen supports vertical display for now
|
||||
bool gui_redraw_fs(Gui* gui) {
|
||||
static bool gui_redraw_fs(Gui* gui) {
|
||||
canvas_set_orientation(gui->canvas, CanvasOrientationHorizontal);
|
||||
canvas_frame_set(gui->canvas, 0, 0, GUI_DISPLAY_WIDTH, GUI_DISPLAY_HEIGHT);
|
||||
ViewPort* view_port = gui_view_port_find_enabled(gui->layers[GuiLayerFullscreen]);
|
||||
|
@ -192,7 +192,7 @@ static void gui_redraw_status_bar(Gui* gui, bool need_attention) {
|
|||
}
|
||||
}
|
||||
|
||||
bool gui_redraw_window(Gui* gui) {
|
||||
static bool gui_redraw_window(Gui* gui) {
|
||||
canvas_set_orientation(gui->canvas, CanvasOrientationHorizontal);
|
||||
canvas_frame_set(gui->canvas, GUI_WINDOW_X, GUI_WINDOW_Y, GUI_WINDOW_WIDTH, GUI_WINDOW_HEIGHT);
|
||||
ViewPort* view_port = gui_view_port_find_enabled(gui->layers[GuiLayerWindow]);
|
||||
|
@ -203,7 +203,7 @@ bool gui_redraw_window(Gui* gui) {
|
|||
return false;
|
||||
}
|
||||
|
||||
bool gui_redraw_desktop(Gui* gui) {
|
||||
static bool gui_redraw_desktop(Gui* gui) {
|
||||
canvas_set_orientation(gui->canvas, CanvasOrientationHorizontal);
|
||||
canvas_frame_set(gui->canvas, 0, 0, GUI_DISPLAY_WIDTH, GUI_DISPLAY_HEIGHT);
|
||||
ViewPort* view_port = gui_view_port_find_enabled(gui->layers[GuiLayerDesktop]);
|
||||
|
@ -215,37 +215,44 @@ bool gui_redraw_desktop(Gui* gui) {
|
|||
return false;
|
||||
}
|
||||
|
||||
void gui_redraw(Gui* gui) {
|
||||
static void gui_redraw(Gui* gui) {
|
||||
furi_assert(gui);
|
||||
gui_lock(gui);
|
||||
|
||||
canvas_reset(gui->canvas);
|
||||
do {
|
||||
if(gui->direct_draw) break;
|
||||
|
||||
if(gui->lockdown) {
|
||||
gui_redraw_desktop(gui);
|
||||
bool need_attention =
|
||||
(gui_view_port_find_enabled(gui->layers[GuiLayerWindow]) != 0 ||
|
||||
gui_view_port_find_enabled(gui->layers[GuiLayerFullscreen]) != 0);
|
||||
gui_redraw_status_bar(gui, need_attention);
|
||||
} else {
|
||||
if(!gui_redraw_fs(gui)) {
|
||||
if(!gui_redraw_window(gui)) {
|
||||
gui_redraw_desktop(gui);
|
||||
canvas_reset(gui->canvas);
|
||||
|
||||
if(gui->lockdown) {
|
||||
gui_redraw_desktop(gui);
|
||||
bool need_attention =
|
||||
(gui_view_port_find_enabled(gui->layers[GuiLayerWindow]) != 0 ||
|
||||
gui_view_port_find_enabled(gui->layers[GuiLayerFullscreen]) != 0);
|
||||
gui_redraw_status_bar(gui, need_attention);
|
||||
} else {
|
||||
if(!gui_redraw_fs(gui)) {
|
||||
if(!gui_redraw_window(gui)) {
|
||||
gui_redraw_desktop(gui);
|
||||
}
|
||||
gui_redraw_status_bar(gui, false);
|
||||
}
|
||||
gui_redraw_status_bar(gui, false);
|
||||
}
|
||||
}
|
||||
|
||||
canvas_commit(gui->canvas);
|
||||
for
|
||||
M_EACH(p, gui->canvas_callback_pair, CanvasCallbackPairArray_t) {
|
||||
p->callback(
|
||||
canvas_get_buffer(gui->canvas), canvas_get_buffer_size(gui->canvas), p->context);
|
||||
}
|
||||
canvas_commit(gui->canvas);
|
||||
for
|
||||
M_EACH(p, gui->canvas_callback_pair, CanvasCallbackPairArray_t) {
|
||||
p->callback(
|
||||
canvas_get_buffer(gui->canvas),
|
||||
canvas_get_buffer_size(gui->canvas),
|
||||
p->context);
|
||||
}
|
||||
} while(false);
|
||||
|
||||
gui_unlock(gui);
|
||||
}
|
||||
|
||||
void gui_input(Gui* gui, InputEvent* input_event) {
|
||||
static void gui_input(Gui* gui, InputEvent* input_event) {
|
||||
furi_assert(gui);
|
||||
furi_assert(input_event);
|
||||
|
||||
|
@ -267,42 +274,48 @@ void gui_input(Gui* gui, InputEvent* input_event) {
|
|||
|
||||
gui_lock(gui);
|
||||
|
||||
ViewPort* view_port = NULL;
|
||||
do {
|
||||
if(gui->direct_draw && !gui->ongoing_input_view_port) {
|
||||
break;
|
||||
}
|
||||
|
||||
if(gui->lockdown) {
|
||||
view_port = gui_view_port_find_enabled(gui->layers[GuiLayerDesktop]);
|
||||
} else {
|
||||
view_port = gui_view_port_find_enabled(gui->layers[GuiLayerFullscreen]);
|
||||
if(!view_port) view_port = gui_view_port_find_enabled(gui->layers[GuiLayerWindow]);
|
||||
if(!view_port) view_port = gui_view_port_find_enabled(gui->layers[GuiLayerDesktop]);
|
||||
}
|
||||
ViewPort* view_port = NULL;
|
||||
|
||||
if(!(gui->ongoing_input & ~key_bit) && input_event->type == InputTypePress) {
|
||||
gui->ongoing_input_view_port = view_port;
|
||||
}
|
||||
if(gui->lockdown) {
|
||||
view_port = gui_view_port_find_enabled(gui->layers[GuiLayerDesktop]);
|
||||
} else {
|
||||
view_port = gui_view_port_find_enabled(gui->layers[GuiLayerFullscreen]);
|
||||
if(!view_port) view_port = gui_view_port_find_enabled(gui->layers[GuiLayerWindow]);
|
||||
if(!view_port) view_port = gui_view_port_find_enabled(gui->layers[GuiLayerDesktop]);
|
||||
}
|
||||
|
||||
if(view_port && view_port == gui->ongoing_input_view_port) {
|
||||
view_port_input(view_port, input_event);
|
||||
} else if(gui->ongoing_input_view_port && input_event->type == InputTypeRelease) {
|
||||
FURI_LOG_D(
|
||||
TAG,
|
||||
"ViewPort changed while key press %p -> %p. Sending key: %s, type: %s, sequence: %p to previous view port",
|
||||
gui->ongoing_input_view_port,
|
||||
view_port,
|
||||
input_get_key_name(input_event->key),
|
||||
input_get_type_name(input_event->type),
|
||||
(void*)input_event->sequence);
|
||||
view_port_input(gui->ongoing_input_view_port, input_event);
|
||||
} else {
|
||||
FURI_LOG_D(
|
||||
TAG,
|
||||
"ViewPort changed while key press %p -> %p. Discarding key: %s, type: %s, sequence: %p",
|
||||
gui->ongoing_input_view_port,
|
||||
view_port,
|
||||
input_get_key_name(input_event->key),
|
||||
input_get_type_name(input_event->type),
|
||||
(void*)input_event->sequence);
|
||||
}
|
||||
if(!(gui->ongoing_input & ~key_bit) && input_event->type == InputTypePress) {
|
||||
gui->ongoing_input_view_port = view_port;
|
||||
}
|
||||
|
||||
if(view_port && view_port == gui->ongoing_input_view_port) {
|
||||
view_port_input(view_port, input_event);
|
||||
} else if(gui->ongoing_input_view_port && input_event->type == InputTypeRelease) {
|
||||
FURI_LOG_D(
|
||||
TAG,
|
||||
"ViewPort changed while key press %p -> %p. Sending key: %s, type: %s, sequence: %p to previous view port",
|
||||
gui->ongoing_input_view_port,
|
||||
view_port,
|
||||
input_get_key_name(input_event->key),
|
||||
input_get_type_name(input_event->type),
|
||||
(void*)input_event->sequence);
|
||||
view_port_input(gui->ongoing_input_view_port, input_event);
|
||||
} else {
|
||||
FURI_LOG_D(
|
||||
TAG,
|
||||
"ViewPort changed while key press %p -> %p. Discarding key: %s, type: %s, sequence: %p",
|
||||
gui->ongoing_input_view_port,
|
||||
view_port,
|
||||
input_get_key_name(input_event->key),
|
||||
input_get_type_name(input_event->type),
|
||||
(void*)input_event->sequence);
|
||||
}
|
||||
} while(false);
|
||||
|
||||
gui_unlock(gui);
|
||||
}
|
||||
|
@ -471,6 +484,31 @@ void gui_set_lockdown(Gui* gui, bool lockdown) {
|
|||
gui_update(gui);
|
||||
}
|
||||
|
||||
Canvas* gui_direct_draw_acquire(Gui* gui) {
|
||||
furi_assert(gui);
|
||||
gui_lock(gui);
|
||||
gui->direct_draw = true;
|
||||
gui_unlock(gui);
|
||||
|
||||
canvas_reset(gui->canvas);
|
||||
canvas_commit(gui->canvas);
|
||||
|
||||
return gui->canvas;
|
||||
}
|
||||
|
||||
void gui_direct_draw_release(Gui* gui) {
|
||||
furi_assert(gui);
|
||||
|
||||
canvas_reset(gui->canvas);
|
||||
canvas_commit(gui->canvas);
|
||||
|
||||
gui_lock(gui);
|
||||
gui->direct_draw = false;
|
||||
gui_unlock(gui);
|
||||
|
||||
gui_update(gui);
|
||||
}
|
||||
|
||||
Gui* gui_alloc() {
|
||||
Gui* gui = malloc(sizeof(Gui));
|
||||
// Thread ID
|
||||
|
|
|
@ -106,6 +106,28 @@ size_t gui_get_framebuffer_size(Gui* gui);
|
|||
*/
|
||||
void gui_set_lockdown(Gui* gui, bool lockdown);
|
||||
|
||||
/** Acquire Direct Draw lock and get Canvas instance
|
||||
*
|
||||
* This method return Canvas instance for use in monopoly mode. Direct draw lock
|
||||
* disables input and draw call dispatch functions in GUI service. No other
|
||||
* applications or services will be able to draw until gui_direct_draw_release
|
||||
* call.
|
||||
*
|
||||
* @param gui The graphical user interface
|
||||
*
|
||||
* @return Canvas instance
|
||||
*/
|
||||
Canvas* gui_direct_draw_acquire(Gui* gui);
|
||||
|
||||
/** Release Direct Draw Lock
|
||||
*
|
||||
* Release Direct Draw Lock, enables Input and Draw call processing. Canvas
|
||||
* acquired in gui_direct_draw_acquire will become invalid after this call.
|
||||
*
|
||||
* @param gui Gui instance
|
||||
*/
|
||||
void gui_direct_draw_release(Gui* gui);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -62,6 +62,7 @@ struct Gui {
|
|||
|
||||
// Layers and Canvas
|
||||
bool lockdown;
|
||||
bool direct_draw;
|
||||
ViewPortArray_t layers[GuiLayerMAX];
|
||||
Canvas* canvas;
|
||||
CanvasCallbackPairArray_t canvas_callback_pair;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
entry,status,name,type,params
|
||||
Version,+,11.3,,
|
||||
Version,+,11.4,,
|
||||
Header,+,applications/services/bt/bt_service/bt.h,,
|
||||
Header,+,applications/services/cli/cli.h,,
|
||||
Header,+,applications/services/cli/cli_vcp.h,,
|
||||
|
@ -602,7 +602,7 @@ Function,+,byte_input_set_result_callback,void,"ByteInput*, ByteInputCallback, B
|
|||
Function,-,bzero,void,"void*, size_t"
|
||||
Function,-,calloc,void*,"size_t, size_t"
|
||||
Function,+,canvas_clear,void,Canvas*
|
||||
Function,-,canvas_commit,void,Canvas*
|
||||
Function,+,canvas_commit,void,Canvas*
|
||||
Function,+,canvas_current_font_height,uint8_t,Canvas*
|
||||
Function,+,canvas_draw_bitmap,void,"Canvas*, uint8_t, uint8_t, uint8_t, uint8_t, const uint8_t*"
|
||||
Function,+,canvas_draw_box,void,"Canvas*, uint8_t, uint8_t, uint8_t, uint8_t"
|
||||
|
@ -631,7 +631,7 @@ Function,+,canvas_glyph_width,uint8_t,"Canvas*, char"
|
|||
Function,+,canvas_height,uint8_t,Canvas*
|
||||
Function,-,canvas_init,Canvas*,
|
||||
Function,+,canvas_invert_color,void,Canvas*
|
||||
Function,-,canvas_reset,void,Canvas*
|
||||
Function,+,canvas_reset,void,Canvas*
|
||||
Function,+,canvas_set_bitmap_mode,void,"Canvas*, _Bool"
|
||||
Function,+,canvas_set_color,void,"Canvas*, Color"
|
||||
Function,+,canvas_set_font,void,"Canvas*, Font"
|
||||
|
@ -1575,6 +1575,8 @@ Function,-,gmtime,tm*,const time_t*
|
|||
Function,-,gmtime_r,tm*,"const time_t*, tm*"
|
||||
Function,+,gui_add_framebuffer_callback,void,"Gui*, GuiCanvasCommitCallback, void*"
|
||||
Function,+,gui_add_view_port,void,"Gui*, ViewPort*, GuiLayer"
|
||||
Function,+,gui_direct_draw_acquire,Canvas*,Gui*
|
||||
Function,+,gui_direct_draw_release,void,Gui*
|
||||
Function,+,gui_get_framebuffer_size,size_t,Gui*
|
||||
Function,+,gui_remove_framebuffer_callback,void,"Gui*, GuiCanvasCommitCallback, void*"
|
||||
Function,+,gui_remove_view_port,void,"Gui*, ViewPort*"
|
||||
|
@ -1877,6 +1879,7 @@ Function,+,menu_set_selected_item,void,"Menu*, uint32_t"
|
|||
Function,-,mf_classic_auth_attempt,_Bool,"FuriHalNfcTxRxContext*, MfClassicAuthContext*, uint64_t"
|
||||
Function,-,mf_classic_auth_init_context,void,"MfClassicAuthContext*, uint8_t"
|
||||
Function,-,mf_classic_authenticate,_Bool,"FuriHalNfcTxRxContext*, uint8_t, uint64_t, MfClassicKey"
|
||||
Function,-,mf_classic_authenticate_skip_activate,_Bool,"FuriHalNfcTxRxContext*, uint8_t, uint64_t, MfClassicKey, _Bool, uint32_t"
|
||||
Function,-,mf_classic_check_card_type,_Bool,"uint8_t, uint8_t, uint8_t"
|
||||
Function,-,mf_classic_dict_add_key,_Bool,"MfClassicDict*, uint8_t*"
|
||||
Function,-,mf_classic_dict_add_key_str,_Bool,"MfClassicDict*, FuriString*"
|
||||
|
|
|
|
@ -680,13 +680,15 @@ void nfc_worker_mf_classic_dict_attack(NfcWorker* nfc_worker) {
|
|||
nfc_worker->callback(NfcWorkerEventNewDictKeyBatch, nfc_worker->context);
|
||||
}
|
||||
furi_hal_nfc_sleep();
|
||||
if(furi_hal_nfc_activate_nfca(200, NULL)) {
|
||||
furi_hal_nfc_sleep();
|
||||
uint32_t cuid;
|
||||
if(furi_hal_nfc_activate_nfca(200, &cuid)) {
|
||||
bool deactivated = false;
|
||||
if(!card_found_notified) {
|
||||
nfc_worker->callback(NfcWorkerEventCardDetected, nfc_worker->context);
|
||||
card_found_notified = true;
|
||||
card_removed_notified = false;
|
||||
nfc_worker_mf_classic_key_attack(nfc_worker, prev_key, &tx_rx, i);
|
||||
deactivated = true;
|
||||
}
|
||||
FURI_LOG_D(
|
||||
TAG,
|
||||
|
@ -696,22 +698,26 @@ void nfc_worker_mf_classic_dict_attack(NfcWorker* nfc_worker) {
|
|||
(uint32_t)key);
|
||||
if(!is_key_a_found) {
|
||||
is_key_a_found = mf_classic_is_key_found(data, i, MfClassicKeyA);
|
||||
if(mf_classic_authenticate(&tx_rx, block_num, key, MfClassicKeyA)) {
|
||||
if(mf_classic_authenticate_skip_activate(
|
||||
&tx_rx, block_num, key, MfClassicKeyA, !deactivated, cuid)) {
|
||||
mf_classic_set_key_found(data, i, MfClassicKeyA, key);
|
||||
FURI_LOG_D(TAG, "Key found");
|
||||
nfc_worker->callback(NfcWorkerEventFoundKeyA, nfc_worker->context);
|
||||
nfc_worker_mf_classic_key_attack(nfc_worker, key, &tx_rx, i + 1);
|
||||
}
|
||||
furi_hal_nfc_sleep();
|
||||
deactivated = true;
|
||||
}
|
||||
if(!is_key_b_found) {
|
||||
is_key_b_found = mf_classic_is_key_found(data, i, MfClassicKeyB);
|
||||
if(mf_classic_authenticate(&tx_rx, block_num, key, MfClassicKeyB)) {
|
||||
if(mf_classic_authenticate_skip_activate(
|
||||
&tx_rx, block_num, key, MfClassicKeyB, !deactivated, cuid)) {
|
||||
FURI_LOG_D(TAG, "Key found");
|
||||
mf_classic_set_key_found(data, i, MfClassicKeyB, key);
|
||||
nfc_worker->callback(NfcWorkerEventFoundKeyB, nfc_worker->context);
|
||||
nfc_worker_mf_classic_key_attack(nfc_worker, key, &tx_rx, i + 1);
|
||||
}
|
||||
deactivated = true;
|
||||
}
|
||||
if(is_key_a_found && is_key_b_found) break;
|
||||
if(nfc_worker->state != NfcWorkerStateMfClassicDictAttack) break;
|
||||
|
|
|
@ -403,15 +403,16 @@ static bool mf_classic_auth(
|
|||
uint32_t block,
|
||||
uint64_t key,
|
||||
MfClassicKey key_type,
|
||||
Crypto1* crypto) {
|
||||
Crypto1* crypto,
|
||||
bool skip_activate,
|
||||
uint32_t cuid) {
|
||||
bool auth_success = false;
|
||||
uint32_t cuid = 0;
|
||||
memset(tx_rx->tx_data, 0, sizeof(tx_rx->tx_data));
|
||||
memset(tx_rx->tx_parity, 0, sizeof(tx_rx->tx_parity));
|
||||
tx_rx->tx_rx_type = FuriHalNfcTxRxTypeDefault;
|
||||
|
||||
do {
|
||||
if(!furi_hal_nfc_activate_nfca(200, &cuid)) break;
|
||||
if(!skip_activate && !furi_hal_nfc_activate_nfca(200, &cuid)) break;
|
||||
if(key_type == MfClassicKeyA) {
|
||||
tx_rx->tx_data[0] = MF_CLASSIC_AUTH_KEY_A_CMD;
|
||||
} else {
|
||||
|
@ -460,7 +461,23 @@ bool mf_classic_authenticate(
|
|||
furi_assert(tx_rx);
|
||||
|
||||
Crypto1 crypto = {};
|
||||
bool key_found = mf_classic_auth(tx_rx, block_num, key, key_type, &crypto);
|
||||
bool key_found = mf_classic_auth(tx_rx, block_num, key, key_type, &crypto, false, 0);
|
||||
furi_hal_nfc_sleep();
|
||||
return key_found;
|
||||
}
|
||||
|
||||
bool mf_classic_authenticate_skip_activate(
|
||||
FuriHalNfcTxRxContext* tx_rx,
|
||||
uint8_t block_num,
|
||||
uint64_t key,
|
||||
MfClassicKey key_type,
|
||||
bool skip_activate,
|
||||
uint32_t cuid) {
|
||||
furi_assert(tx_rx);
|
||||
|
||||
Crypto1 crypto = {};
|
||||
bool key_found =
|
||||
mf_classic_auth(tx_rx, block_num, key, key_type, &crypto, skip_activate, cuid);
|
||||
furi_hal_nfc_sleep();
|
||||
return key_found;
|
||||
}
|
||||
|
@ -483,7 +500,9 @@ bool mf_classic_auth_attempt(
|
|||
mf_classic_get_first_block_num_of_sector(auth_ctx->sector),
|
||||
key,
|
||||
MfClassicKeyA,
|
||||
&crypto)) {
|
||||
&crypto,
|
||||
false,
|
||||
0)) {
|
||||
auth_ctx->key_a = key;
|
||||
found_key = true;
|
||||
}
|
||||
|
@ -500,7 +519,9 @@ bool mf_classic_auth_attempt(
|
|||
mf_classic_get_first_block_num_of_sector(auth_ctx->sector),
|
||||
key,
|
||||
MfClassicKeyB,
|
||||
&crypto)) {
|
||||
&crypto,
|
||||
false,
|
||||
0)) {
|
||||
auth_ctx->key_b = key;
|
||||
found_key = true;
|
||||
}
|
||||
|
@ -568,7 +589,7 @@ void mf_classic_read_sector(FuriHalNfcTxRxContext* tx_rx, MfClassicData* data, u
|
|||
if(!key_a_found) break;
|
||||
FURI_LOG_D(TAG, "Try to read blocks with key A");
|
||||
key = nfc_util_bytes2num(sec_tr->key_a, sizeof(sec_tr->key_a));
|
||||
if(!mf_classic_auth(tx_rx, start_block, key, MfClassicKeyA, &crypto)) break;
|
||||
if(!mf_classic_auth(tx_rx, start_block, key, MfClassicKeyA, &crypto, false, 0)) break;
|
||||
for(size_t i = start_block; i < start_block + total_blocks; i++) {
|
||||
if(!mf_classic_is_block_read(data, i)) {
|
||||
if(mf_classic_read_block(tx_rx, &crypto, i, &block_tmp)) {
|
||||
|
@ -587,7 +608,7 @@ void mf_classic_read_sector(FuriHalNfcTxRxContext* tx_rx, MfClassicData* data, u
|
|||
FURI_LOG_D(TAG, "Try to read blocks with key B");
|
||||
key = nfc_util_bytes2num(sec_tr->key_b, sizeof(sec_tr->key_b));
|
||||
furi_hal_nfc_sleep();
|
||||
if(!mf_classic_auth(tx_rx, start_block, key, MfClassicKeyB, &crypto)) break;
|
||||
if(!mf_classic_auth(tx_rx, start_block, key, MfClassicKeyB, &crypto, false, 0)) break;
|
||||
for(size_t i = start_block; i < start_block + total_blocks; i++) {
|
||||
if(!mf_classic_is_block_read(data, i)) {
|
||||
if(mf_classic_read_block(tx_rx, &crypto, i, &block_tmp)) {
|
||||
|
@ -631,7 +652,7 @@ static bool mf_classic_read_sector_with_reader(
|
|||
}
|
||||
|
||||
// Auth to first block in sector
|
||||
if(!mf_classic_auth(tx_rx, first_block, key, key_type, crypto)) {
|
||||
if(!mf_classic_auth(tx_rx, first_block, key, key_type, crypto, false, 0)) {
|
||||
// Set key to MF_CLASSIC_NO_KEY to prevent further attempts
|
||||
if(key_type == MfClassicKeyA) {
|
||||
sector_reader->key_a = MF_CLASSIC_NO_KEY;
|
||||
|
@ -961,7 +982,7 @@ bool mf_classic_write_block(
|
|||
|
||||
do {
|
||||
furi_hal_nfc_sleep();
|
||||
if(!mf_classic_auth(tx_rx, block_num, key, key_type, &crypto)) {
|
||||
if(!mf_classic_auth(tx_rx, block_num, key, key_type, &crypto, false, 0)) {
|
||||
FURI_LOG_D(TAG, "Auth fail");
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -156,6 +156,14 @@ bool mf_classic_authenticate(
|
|||
uint64_t key,
|
||||
MfClassicKey key_type);
|
||||
|
||||
bool mf_classic_authenticate_skip_activate(
|
||||
FuriHalNfcTxRxContext* tx_rx,
|
||||
uint8_t block_num,
|
||||
uint64_t key,
|
||||
MfClassicKey key_type,
|
||||
bool skip_activate,
|
||||
uint32_t cuid);
|
||||
|
||||
bool mf_classic_auth_attempt(
|
||||
FuriHalNfcTxRxContext* tx_rx,
|
||||
MfClassicAuthContext* auth_ctx,
|
||||
|
|
Loading…
Reference in a new issue