Disable NFC in esubghz chat, works again --nobuild

This commit is contained in:
Willy-JL
2023-11-27 05:47:34 +00:00
parent ebd30aed78
commit 2ed78baa45
8 changed files with 353 additions and 353 deletions

View File

@@ -1,5 +1,5 @@
App(
appid=".esubghz_chat",
appid="esubghz_chat",
name="Enhanced Sub-Ghz Chat",
apptype=FlipperAppType.EXTERNAL,
entry_point="esubghz_chat",

View File

@@ -610,16 +610,16 @@ int32_t esubghz_chat(const char* args) {
goto err_alloc_worker;
}
state->nfc_worker = nfc_worker_alloc();
if(state->nfc_worker == NULL) {
goto err_alloc_nworker;
}
// state->nfc_worker = nfc_worker_alloc();
// if(state->nfc_worker == NULL) {
// goto err_alloc_nworker;
// }
state->nfc_dev_data = malloc(sizeof(NfcDeviceData));
if(state->nfc_dev_data == NULL) {
goto err_alloc_ndevdata;
}
memset(state->nfc_dev_data, 0, sizeof(NfcDeviceData));
// state->nfc_dev_data = malloc(sizeof(NfcDeviceData));
// if(state->nfc_dev_data == NULL) {
// goto err_alloc_ndevdata;
// }
// memset(state->nfc_dev_data, 0, sizeof(NfcDeviceData));
state->crypto_ctx = crypto_ctx_alloc();
if(state->crypto_ctx == NULL) {
@@ -715,7 +715,7 @@ int32_t esubghz_chat(const char* args) {
}
/* if it is running, stop the NFC worker */
nfc_worker_stop(state->nfc_worker);
// nfc_worker_stop(state->nfc_worker);
err = 0;
@@ -740,10 +740,10 @@ int32_t esubghz_chat(const char* args) {
crypto_ctx_clear(state->crypto_ctx);
/* clear nfc data */
if(state->nfc_dev_data->parsed_data != NULL) {
furi_string_free(state->nfc_dev_data->parsed_data);
}
crypto_explicit_bzero(state->nfc_dev_data, sizeof(NfcDeviceData));
// if(state->nfc_dev_data->parsed_data != NULL) {
// furi_string_free(state->nfc_dev_data->parsed_data);
// }
// crypto_explicit_bzero(state->nfc_dev_data, sizeof(NfcDeviceData));
/* deinit devices */
radio_device_loader_end(state->subghz_device);
@@ -758,12 +758,12 @@ int32_t esubghz_chat(const char* args) {
crypto_ctx_free(state->crypto_ctx);
err_alloc_crypto:
free(state->nfc_dev_data);
// free(state->nfc_dev_data);
err_alloc_ndevdata:
nfc_worker_free(state->nfc_worker);
// err_alloc_ndevdata:
// nfc_worker_free(state->nfc_worker);
err_alloc_nworker:
// err_alloc_nworker:
subghz_tx_rx_worker_free(state->subghz_worker);
err_alloc_worker:

View File

@@ -11,7 +11,7 @@
#include <gui/modules/text_box.h>
#include <gui/modules/text_input.h>
#include <notification/notification_messages.h>
#include <lib/nfc/nfc_worker.h>
// #include <lib/nfc/nfc_worker.h>
#include <lib/subghz/subghz_tx_rx_worker.h>
#include <toolbox/sha256.h>
@@ -59,8 +59,8 @@ typedef struct {
const SubGhzDevice* subghz_device;
// for NFC
NfcWorker* nfc_worker;
NfcDeviceData* nfc_dev_data;
// NfcWorker* nfc_worker;
// NfcDeviceData* nfc_dev_data;
// message assembly before TX
FuriString* name_prefix;
@@ -101,7 +101,7 @@ typedef enum {
ESubGhzChatEvent_KeyMenuPassword,
ESubGhzChatEvent_KeyMenuHexKey,
ESubGhzChatEvent_KeyMenuGenKey,
ESubGhzChatEvent_KeyMenuReadKeyFromNfc,
// ESubGhzChatEvent_KeyMenuReadKeyFromNfc,
ESubGhzChatEvent_KeyReadPopupFailed,
ESubGhzChatEvent_KeyReadPopupSucceeded,
ESubGhzChatEvent_PassEntered,

View File

@@ -88,7 +88,7 @@ void scene_on_enter_key_display(void* context) {
dialog_ex_set_left_button_text(state->key_display, "Back");
if(state->encrypted) {
dialog_ex_set_center_button_text(state->key_display, "Share");
// dialog_ex_set_center_button_text(state->key_display, "Share");
}
dialog_ex_set_result_callback(state->key_display, key_display_result_cb);
@@ -120,10 +120,10 @@ bool scene_on_event_key_display(void* context, SceneManagerEvent event) {
break;
/* open key sharing popup */
case ESubGhzChatEvent_KeyDisplayShare:
scene_manager_next_scene(state->scene_manager, ESubGhzChatScene_KeySharePopup);
consumed = true;
break;
// case ESubGhzChatEvent_KeyDisplayShare:
// scene_manager_next_scene(state->scene_manager, ESubGhzChatScene_KeySharePopup);
// consumed = true;
// break;
}
break;

View File

@@ -5,7 +5,7 @@ typedef enum {
ESubGhzChatKeyMenuItems_Password,
ESubGhzChatKeyMenuItems_HexKey,
ESubGhzChatKeyMenuItems_GenKey,
ESubGhzChatKeyMenuItems_ReadKeyFromNfc,
// ESubGhzChatKeyMenuItems_ReadKeyFromNfc,
} ESubGhzChatKeyMenuItems;
static void key_menu_cb(void* context, uint32_t index) {
@@ -52,10 +52,10 @@ static void key_menu_cb(void* context, uint32_t index) {
view_dispatcher_send_custom_event(state->view_dispatcher, ESubGhzChatEvent_KeyMenuGenKey);
break;
case ESubGhzChatKeyMenuItems_ReadKeyFromNfc:
view_dispatcher_send_custom_event(
state->view_dispatcher, ESubGhzChatEvent_KeyMenuReadKeyFromNfc);
break;
// case ESubGhzChatKeyMenuItems_ReadKeyFromNfc:
// view_dispatcher_send_custom_event(
// state->view_dispatcher, ESubGhzChatEvent_KeyMenuReadKeyFromNfc);
// break;
default:
break;
@@ -98,13 +98,13 @@ void scene_on_enter_key_menu(void* context) {
ESubGhzChatKeyMenuItems_GenKey,
key_menu_cb,
state);
menu_add_item(
state->menu,
"Read Key from NFC",
&I_Nfc_14px,
ESubGhzChatKeyMenuItems_ReadKeyFromNfc,
key_menu_cb,
state);
// menu_add_item(
// state->menu,
// "Read Key from NFC",
// &I_Nfc_14px,
// ESubGhzChatKeyMenuItems_ReadKeyFromNfc,
// key_menu_cb,
// state);
view_dispatcher_switch_to_view(state->view_dispatcher, ESubGhzChatView_Menu);
}
@@ -140,11 +140,11 @@ bool scene_on_event_key_menu(void* context, SceneManagerEvent event) {
consumed = true;
break;
/* switch to hex key read scene */
case ESubGhzChatEvent_KeyMenuReadKeyFromNfc:
scene_manager_next_scene(state->scene_manager, ESubGhzChatScene_KeyReadPopup);
consumed = true;
break;
/* switch to hex key read scene */
// case ESubGhzChatEvent_KeyMenuReadKeyFromNfc:
// scene_manager_next_scene(state->scene_manager, ESubGhzChatScene_KeyReadPopup);
// consumed = true;
// break;
}
break;

View File

@@ -1,273 +1,273 @@
#include "../esubghz_chat_i.h"
#include "../helpers/nfc_helpers.h"
// #include "../esubghz_chat_i.h"
// #include "../helpers/nfc_helpers.h"
typedef enum {
KeyReadPopupState_Idle,
KeyReadPopupState_Detecting,
KeyReadPopupState_Reading,
KeyReadPopupState_Fail,
KeyReadPopupState_Success,
} KeyReadPopupState;
// typedef enum {
// KeyReadPopupState_Idle,
// KeyReadPopupState_Detecting,
// KeyReadPopupState_Reading,
// KeyReadPopupState_Fail,
// KeyReadPopupState_Success,
// } KeyReadPopupState;
static bool read_worker_cb(NfcWorkerEvent event, void* context) {
furi_assert(context);
ESubGhzChatState* state = context;
// static bool read_worker_cb(NfcWorkerEvent event, void* context) {
// furi_assert(context);
// ESubGhzChatState* state = context;
view_dispatcher_send_custom_event(state->view_dispatcher, event);
// view_dispatcher_send_custom_event(state->view_dispatcher, event);
return true;
}
// return true;
// }
static void key_read_popup_timeout_cb(void* context) {
furi_assert(context);
ESubGhzChatState* state = context;
// static void key_read_popup_timeout_cb(void* context) {
// furi_assert(context);
// ESubGhzChatState* state = context;
uint32_t cur_state =
scene_manager_get_scene_state(state->scene_manager, ESubGhzChatScene_KeyReadPopup);
// uint32_t cur_state =
// scene_manager_get_scene_state(state->scene_manager, ESubGhzChatScene_KeyReadPopup);
/* done displaying our failure */
if(cur_state == KeyReadPopupState_Fail) {
view_dispatcher_send_custom_event(
state->view_dispatcher, ESubGhzChatEvent_KeyReadPopupFailed);
/* done displaying our success */
} else if(cur_state == KeyReadPopupState_Success) {
view_dispatcher_send_custom_event(
state->view_dispatcher, ESubGhzChatEvent_KeyReadPopupSucceeded);
}
}
// /* done displaying our failure */
// if(cur_state == KeyReadPopupState_Fail) {
// view_dispatcher_send_custom_event(
// state->view_dispatcher, ESubGhzChatEvent_KeyReadPopupFailed);
// /* done displaying our success */
// } else if(cur_state == KeyReadPopupState_Success) {
// view_dispatcher_send_custom_event(
// state->view_dispatcher, ESubGhzChatEvent_KeyReadPopupSucceeded);
// }
// }
struct ReplayDictNfcReaderContext {
uint8_t* cur;
uint8_t* max;
};
// struct ReplayDictNfcReaderContext {
// uint8_t* cur;
// uint8_t* max;
// };
static bool replay_dict_nfc_reader(uint64_t* run_id, uint32_t* counter, void* context) {
struct ReplayDictNfcReaderContext* ctx = (struct ReplayDictNfcReaderContext*)context;
// static bool replay_dict_nfc_reader(uint64_t* run_id, uint32_t* counter, void* context) {
// struct ReplayDictNfcReaderContext* ctx = (struct ReplayDictNfcReaderContext*)context;
if(ctx->cur + sizeof(struct ReplayDictNfcEntry) > ctx->max) {
return false;
}
// if(ctx->cur + sizeof(struct ReplayDictNfcEntry) > ctx->max) {
// return false;
// }
struct ReplayDictNfcEntry* entry = (struct ReplayDictNfcEntry*)ctx->cur;
*run_id = entry->run_id;
*counter = __ntohl(entry->counter);
// struct ReplayDictNfcEntry* entry = (struct ReplayDictNfcEntry*)ctx->cur;
// *run_id = entry->run_id;
// *counter = __ntohl(entry->counter);
ctx->cur += sizeof(struct ReplayDictNfcEntry);
// ctx->cur += sizeof(struct ReplayDictNfcEntry);
return true;
}
// return true;
// }
static bool key_read_popup_handle_key_read(ESubGhzChatState* state) {
NfcDeviceData* dev_data = state->nfc_dev_data;
// static bool key_read_popup_handle_key_read(ESubGhzChatState* state) {
// NfcDeviceData* dev_data = state->nfc_dev_data;
/* check for config pages */
if(dev_data->mf_ul_data.data_read < NFC_CONFIG_PAGES * 4) {
return false;
}
// /* check for config pages */
// if(dev_data->mf_ul_data.data_read < NFC_CONFIG_PAGES * 4) {
// return false;
// }
size_t data_read = dev_data->mf_ul_data.data_read - (NFC_CONFIG_PAGES * 4);
// size_t data_read = dev_data->mf_ul_data.data_read - (NFC_CONFIG_PAGES * 4);
/* check if key was transmitted */
if(data_read < KEY_BITS / 8) {
return false;
}
// /* check if key was transmitted */
// if(data_read < KEY_BITS / 8) {
// return false;
// }
/* initiate the crypto context */
bool ret = crypto_ctx_set_key(
state->crypto_ctx, dev_data->mf_ul_data.data, state->name_prefix, furi_get_tick());
// /* initiate the crypto context */
// bool ret = crypto_ctx_set_key(
// state->crypto_ctx, dev_data->mf_ul_data.data, state->name_prefix, furi_get_tick());
/* cleanup */
crypto_explicit_bzero(dev_data->mf_ul_data.data, KEY_BITS / 8);
// /* cleanup */
// crypto_explicit_bzero(dev_data->mf_ul_data.data, KEY_BITS / 8);
if(!ret) {
crypto_ctx_clear(state->crypto_ctx);
return false;
}
// if(!ret) {
// crypto_ctx_clear(state->crypto_ctx);
// return false;
// }
/* read the frequency */
if(data_read >= (KEY_BITS / 8) + sizeof(struct FreqNfcEntry)) {
struct FreqNfcEntry* freq_entry =
(struct FreqNfcEntry*)(dev_data->mf_ul_data.data + (KEY_BITS / 8));
state->frequency = __ntohl(freq_entry->frequency);
}
// /* read the frequency */
// if(data_read >= (KEY_BITS / 8) + sizeof(struct FreqNfcEntry)) {
// struct FreqNfcEntry* freq_entry =
// (struct FreqNfcEntry*)(dev_data->mf_ul_data.data + (KEY_BITS / 8));
// state->frequency = __ntohl(freq_entry->frequency);
// }
/* read the replay dict */
struct ReplayDictNfcReaderContext rd_ctx = {
.cur = dev_data->mf_ul_data.data + (KEY_BITS / 8) + sizeof(struct FreqNfcEntry),
.max =
dev_data->mf_ul_data.data + (data_read < NFC_MAX_BYTES ? data_read : NFC_MAX_BYTES)};
// /* read the replay dict */
// struct ReplayDictNfcReaderContext rd_ctx = {
// .cur = dev_data->mf_ul_data.data + (KEY_BITS / 8) + sizeof(struct FreqNfcEntry),
// .max =
// dev_data->mf_ul_data.data + (data_read < NFC_MAX_BYTES ? data_read : NFC_MAX_BYTES)};
crypto_ctx_read_replay_dict(state->crypto_ctx, replay_dict_nfc_reader, &rd_ctx);
// crypto_ctx_read_replay_dict(state->crypto_ctx, replay_dict_nfc_reader, &rd_ctx);
/* set encrypted flag */
state->encrypted = true;
// /* set encrypted flag */
// state->encrypted = true;
return true;
}
// return true;
// }
static void key_read_popup_set_state(ESubGhzChatState* state, KeyReadPopupState new_state) {
uint32_t cur_state =
scene_manager_get_scene_state(state->scene_manager, ESubGhzChatScene_KeyReadPopup);
if(cur_state == new_state) {
return;
}
// static void key_read_popup_set_state(ESubGhzChatState* state, KeyReadPopupState new_state) {
// uint32_t cur_state =
// scene_manager_get_scene_state(state->scene_manager, ESubGhzChatScene_KeyReadPopup);
// if(cur_state == new_state) {
// return;
// }
if(new_state == KeyReadPopupState_Detecting) {
popup_reset(state->nfc_popup);
popup_disable_timeout(state->nfc_popup);
popup_set_text(state->nfc_popup, "Tap Flipper\n to sender", 97, 24, AlignCenter, AlignTop);
popup_set_icon(state->nfc_popup, 0, 8, &I_NFC_manual_60x50);
notification_message(state->notification, &sequence_blink_start_cyan);
} else if(new_state == KeyReadPopupState_Reading) {
popup_reset(state->nfc_popup);
popup_disable_timeout(state->nfc_popup);
popup_set_header(
state->nfc_popup,
"Reading key\nDon't "
"move...",
85,
24,
AlignCenter,
AlignTop);
popup_set_icon(state->nfc_popup, 12, 23, &I_Loading_24);
notification_message(state->notification, &sequence_blink_start_yellow);
} else if(new_state == KeyReadPopupState_Fail) {
nfc_worker_stop(state->nfc_worker);
// if(new_state == KeyReadPopupState_Detecting) {
// popup_reset(state->nfc_popup);
// popup_disable_timeout(state->nfc_popup);
// popup_set_text(state->nfc_popup, "Tap Flipper\n to sender", 97, 24, AlignCenter, AlignTop);
// popup_set_icon(state->nfc_popup, 0, 8, &I_NFC_manual_60x50);
// notification_message(state->notification, &sequence_blink_start_cyan);
// } else if(new_state == KeyReadPopupState_Reading) {
// popup_reset(state->nfc_popup);
// popup_disable_timeout(state->nfc_popup);
// popup_set_header(
// state->nfc_popup,
// "Reading key\nDon't "
// "move...",
// 85,
// 24,
// AlignCenter,
// AlignTop);
// popup_set_icon(state->nfc_popup, 12, 23, &I_Loading_24);
// notification_message(state->notification, &sequence_blink_start_yellow);
// } else if(new_state == KeyReadPopupState_Fail) {
// nfc_worker_stop(state->nfc_worker);
popup_reset(state->nfc_popup);
popup_set_header(state->nfc_popup, "Failure!", 64, 2, AlignCenter, AlignTop);
popup_set_text(state->nfc_popup, "Failed\nto read\nkey.", 78, 16, AlignLeft, AlignTop);
popup_set_icon(state->nfc_popup, 21, 13, &I_Cry_dolph_55x52);
// popup_reset(state->nfc_popup);
// popup_set_header(state->nfc_popup, "Failure!", 64, 2, AlignCenter, AlignTop);
// popup_set_text(state->nfc_popup, "Failed\nto read\nkey.", 78, 16, AlignLeft, AlignTop);
// popup_set_icon(state->nfc_popup, 21, 13, &I_Cry_dolph_55x52);
popup_set_timeout(state->nfc_popup, KEY_READ_POPUP_MS);
popup_set_context(state->nfc_popup, state);
popup_set_callback(state->nfc_popup, key_read_popup_timeout_cb);
popup_enable_timeout(state->nfc_popup);
// popup_set_timeout(state->nfc_popup, KEY_READ_POPUP_MS);
// popup_set_context(state->nfc_popup, state);
// popup_set_callback(state->nfc_popup, key_read_popup_timeout_cb);
// popup_enable_timeout(state->nfc_popup);
notification_message(state->notification, &sequence_blink_stop);
} else if(new_state == KeyReadPopupState_Success) {
nfc_worker_stop(state->nfc_worker);
// notification_message(state->notification, &sequence_blink_stop);
// } else if(new_state == KeyReadPopupState_Success) {
// nfc_worker_stop(state->nfc_worker);
popup_reset(state->nfc_popup);
popup_set_header(state->nfc_popup, "Key\nread!", 13, 22, AlignLeft, AlignBottom);
popup_set_icon(state->nfc_popup, 32, 5, &I_DolphinNice_96x59);
// popup_reset(state->nfc_popup);
// popup_set_header(state->nfc_popup, "Key\nread!", 13, 22, AlignLeft, AlignBottom);
// popup_set_icon(state->nfc_popup, 32, 5, &I_DolphinNice_96x59);
popup_set_timeout(state->nfc_popup, KEY_READ_POPUP_MS);
popup_set_context(state->nfc_popup, state);
popup_set_callback(state->nfc_popup, key_read_popup_timeout_cb);
popup_enable_timeout(state->nfc_popup);
// popup_set_timeout(state->nfc_popup, KEY_READ_POPUP_MS);
// popup_set_context(state->nfc_popup, state);
// popup_set_callback(state->nfc_popup, key_read_popup_timeout_cb);
// popup_enable_timeout(state->nfc_popup);
notification_message(state->notification, &sequence_success);
notification_message(state->notification, &sequence_blink_stop);
}
// notification_message(state->notification, &sequence_success);
// notification_message(state->notification, &sequence_blink_stop);
// }
scene_manager_set_scene_state(state->scene_manager, ESubGhzChatScene_KeyReadPopup, new_state);
// scene_manager_set_scene_state(state->scene_manager, ESubGhzChatScene_KeyReadPopup, new_state);
view_dispatcher_switch_to_view(state->view_dispatcher, ESubGhzChatView_NfcPopup);
}
// view_dispatcher_switch_to_view(state->view_dispatcher, ESubGhzChatView_NfcPopup);
// }
/* Prepares the key share read scene. */
void scene_on_enter_key_read_popup(void* context) {
FURI_LOG_T(APPLICATION_NAME, "scene_on_enter_key_read_popup");
// /* Prepares the key share read scene. */
// void scene_on_enter_key_read_popup(void* context) {
// FURI_LOG_T(APPLICATION_NAME, "scene_on_enter_key_read_popup");
furi_assert(context);
ESubGhzChatState* state = context;
// furi_assert(context);
// ESubGhzChatState* state = context;
key_read_popup_set_state(state, KeyReadPopupState_Detecting);
// key_read_popup_set_state(state, KeyReadPopupState_Detecting);
state->nfc_dev_data->parsed_data = furi_string_alloc();
if(state->nfc_dev_data->parsed_data == NULL) {
/* can't do anything here, crash */
furi_check(0);
}
// state->nfc_dev_data->parsed_data = furi_string_alloc();
// if(state->nfc_dev_data->parsed_data == NULL) {
// /* can't do anything here, crash */
// furi_check(0);
// }
nfc_worker_start(
state->nfc_worker, NfcWorkerStateRead, state->nfc_dev_data, read_worker_cb, state);
}
// nfc_worker_start(
// state->nfc_worker, NfcWorkerStateRead, state->nfc_dev_data, read_worker_cb, state);
// }
/* Handles scene manager events for the key read popup scene. */
bool scene_on_event_key_read_popup(void* context, SceneManagerEvent event) {
FURI_LOG_T(APPLICATION_NAME, "scene_on_event_key_read_popup");
// /* Handles scene manager events for the key read popup scene. */
// bool scene_on_event_key_read_popup(void* context, SceneManagerEvent event) {
// FURI_LOG_T(APPLICATION_NAME, "scene_on_event_key_read_popup");
furi_assert(context);
ESubGhzChatState* state = context;
// furi_assert(context);
// ESubGhzChatState* state = context;
bool consumed = false;
// bool consumed = false;
switch(event.type) {
case SceneManagerEventTypeCustom:
switch(event.event) {
/* card detected */
case NfcWorkerEventCardDetected:
key_read_popup_set_state(state, KeyReadPopupState_Reading);
consumed = true;
break;
// switch(event.type) {
// case SceneManagerEventTypeCustom:
// switch(event.event) {
// /* card detected */
// case NfcWorkerEventCardDetected:
// key_read_popup_set_state(state, KeyReadPopupState_Reading);
// consumed = true;
// break;
/* no card detected */
case NfcWorkerEventNoCardDetected:
key_read_popup_set_state(state, KeyReadPopupState_Detecting);
consumed = true;
break;
// /* no card detected */
// case NfcWorkerEventNoCardDetected:
// key_read_popup_set_state(state, KeyReadPopupState_Detecting);
// consumed = true;
// break;
/* key probably read */
case NfcWorkerEventReadMfUltralight:
if(key_read_popup_handle_key_read(state)) {
key_read_popup_set_state(state, KeyReadPopupState_Success);
} else {
key_read_popup_set_state(state, KeyReadPopupState_Fail);
}
consumed = true;
break;
// /* key probably read */
// case NfcWorkerEventReadMfUltralight:
// if(key_read_popup_handle_key_read(state)) {
// key_read_popup_set_state(state, KeyReadPopupState_Success);
// } else {
// key_read_popup_set_state(state, KeyReadPopupState_Fail);
// }
// consumed = true;
// break;
/* close the popup and go back */
case ESubGhzChatEvent_KeyReadPopupFailed:
if(!scene_manager_previous_scene(state->scene_manager)) {
view_dispatcher_stop(state->view_dispatcher);
}
consumed = true;
break;
// /* close the popup and go back */
// case ESubGhzChatEvent_KeyReadPopupFailed:
// if(!scene_manager_previous_scene(state->scene_manager)) {
// view_dispatcher_stop(state->view_dispatcher);
// }
// consumed = true;
// break;
/* success, go to frequency input */
case ESubGhzChatEvent_KeyReadPopupSucceeded:
scene_manager_next_scene(state->scene_manager, ESubGhzChatScene_FreqInput);
consumed = true;
break;
// /* success, go to frequency input */
// case ESubGhzChatEvent_KeyReadPopupSucceeded:
// scene_manager_next_scene(state->scene_manager, ESubGhzChatScene_FreqInput);
// consumed = true;
// break;
/* something else happend, treat as failure */
default:
key_read_popup_set_state(state, KeyReadPopupState_Fail);
consumed = true;
break;
}
// /* something else happend, treat as failure */
// default:
// key_read_popup_set_state(state, KeyReadPopupState_Fail);
// consumed = true;
// break;
// }
break;
// break;
default:
consumed = false;
break;
}
// default:
// consumed = false;
// break;
// }
return consumed;
}
// return consumed;
// }
/* Cleans up the key read popup scene. */
void scene_on_exit_key_read_popup(void* context) {
FURI_LOG_T(APPLICATION_NAME, "scene_on_exit_key_read_popup");
// /* Cleans up the key read popup scene. */
// void scene_on_exit_key_read_popup(void* context) {
// FURI_LOG_T(APPLICATION_NAME, "scene_on_exit_key_read_popup");
furi_assert(context);
ESubGhzChatState* state = context;
// furi_assert(context);
// ESubGhzChatState* state = context;
popup_reset(state->nfc_popup);
scene_manager_set_scene_state(
state->scene_manager, ESubGhzChatScene_KeyReadPopup, KeyReadPopupState_Idle);
// popup_reset(state->nfc_popup);
// scene_manager_set_scene_state(
// state->scene_manager, ESubGhzChatScene_KeyReadPopup, KeyReadPopupState_Idle);
notification_message(state->notification, &sequence_blink_stop);
// notification_message(state->notification, &sequence_blink_stop);
nfc_worker_stop(state->nfc_worker);
// nfc_worker_stop(state->nfc_worker);
crypto_explicit_bzero(state->nfc_dev_data->mf_ul_data.data, KEY_BITS / 8);
if(state->nfc_dev_data->parsed_data != NULL) {
furi_string_free(state->nfc_dev_data->parsed_data);
}
memset(state->nfc_dev_data, 0, sizeof(NfcDeviceData));
}
// crypto_explicit_bzero(state->nfc_dev_data->mf_ul_data.data, KEY_BITS / 8);
// if(state->nfc_dev_data->parsed_data != NULL) {
// furi_string_free(state->nfc_dev_data->parsed_data);
// }
// memset(state->nfc_dev_data, 0, sizeof(NfcDeviceData));
// }

View File

@@ -1,124 +1,124 @@
#include "../esubghz_chat_i.h"
#include "../helpers/nfc_helpers.h"
// #include "../esubghz_chat_i.h"
// #include "../helpers/nfc_helpers.h"
struct ReplayDictNfcWriterContext {
uint8_t* cur;
uint8_t* max;
};
// struct ReplayDictNfcWriterContext {
// uint8_t* cur;
// uint8_t* max;
// };
static bool replay_dict_nfc_writer(uint64_t run_id, uint32_t counter, void* context) {
struct ReplayDictNfcWriterContext* ctx = (struct ReplayDictNfcWriterContext*)context;
// static bool replay_dict_nfc_writer(uint64_t run_id, uint32_t counter, void* context) {
// struct ReplayDictNfcWriterContext* ctx = (struct ReplayDictNfcWriterContext*)context;
struct ReplayDictNfcEntry entry = {.run_id = run_id, .counter = __htonl(counter), .unused = 0};
// struct ReplayDictNfcEntry entry = {.run_id = run_id, .counter = __htonl(counter), .unused = 0};
if(ctx->cur + sizeof(entry) > ctx->max) {
return false;
}
// if(ctx->cur + sizeof(entry) > ctx->max) {
// return false;
// }
memcpy(ctx->cur, &entry, sizeof(entry));
ctx->cur += sizeof(entry);
// memcpy(ctx->cur, &entry, sizeof(entry));
// ctx->cur += sizeof(entry);
return true;
}
// return true;
// }
static void prepare_nfc_dev_data(ESubGhzChatState* state) {
NfcDeviceData* dev_data = state->nfc_dev_data;
// static void prepare_nfc_dev_data(ESubGhzChatState* state) {
// NfcDeviceData* dev_data = state->nfc_dev_data;
dev_data->protocol = NfcDeviceProtocolMifareUl;
furi_hal_random_fill_buf(dev_data->nfc_data.uid, 7);
dev_data->nfc_data.uid_len = 7;
dev_data->nfc_data.atqa[0] = 0x44;
dev_data->nfc_data.atqa[1] = 0x00;
dev_data->nfc_data.sak = 0x00;
// dev_data->protocol = NfcDeviceProtocolMifareUl;
// furi_hal_random_fill_buf(dev_data->nfc_data.uid, 7);
// dev_data->nfc_data.uid_len = 7;
// dev_data->nfc_data.atqa[0] = 0x44;
// dev_data->nfc_data.atqa[1] = 0x00;
// dev_data->nfc_data.sak = 0x00;
dev_data->mf_ul_data.type = MfUltralightTypeNTAG215;
dev_data->mf_ul_data.version.header = 0x00;
dev_data->mf_ul_data.version.vendor_id = 0x04;
dev_data->mf_ul_data.version.prod_type = 0x04;
dev_data->mf_ul_data.version.prod_subtype = 0x02;
dev_data->mf_ul_data.version.prod_ver_major = 0x01;
dev_data->mf_ul_data.version.prod_ver_minor = 0x00;
dev_data->mf_ul_data.version.storage_size = 0x11;
dev_data->mf_ul_data.version.protocol_type = 0x03;
// dev_data->mf_ul_data.type = MfUltralightTypeNTAG215;
// dev_data->mf_ul_data.version.header = 0x00;
// dev_data->mf_ul_data.version.vendor_id = 0x04;
// dev_data->mf_ul_data.version.prod_type = 0x04;
// dev_data->mf_ul_data.version.prod_subtype = 0x02;
// dev_data->mf_ul_data.version.prod_ver_major = 0x01;
// dev_data->mf_ul_data.version.prod_ver_minor = 0x00;
// dev_data->mf_ul_data.version.storage_size = 0x11;
// dev_data->mf_ul_data.version.protocol_type = 0x03;
size_t data_written = 0;
// size_t data_written = 0;
/* write key */
crypto_ctx_get_key(state->crypto_ctx, dev_data->mf_ul_data.data);
data_written += (KEY_BITS / 8);
// /* write key */
// crypto_ctx_get_key(state->crypto_ctx, dev_data->mf_ul_data.data);
// data_written += (KEY_BITS / 8);
/* write frequency */
struct FreqNfcEntry* freq_entry =
(struct FreqNfcEntry*)(dev_data->mf_ul_data.data + data_written);
freq_entry->frequency = __htonl(state->frequency);
freq_entry->unused1 = 0;
freq_entry->unused2 = 0;
freq_entry->unused3 = 0;
data_written += sizeof(struct FreqNfcEntry);
// /* write frequency */
// struct FreqNfcEntry* freq_entry =
// (struct FreqNfcEntry*)(dev_data->mf_ul_data.data + data_written);
// freq_entry->frequency = __htonl(state->frequency);
// freq_entry->unused1 = 0;
// freq_entry->unused2 = 0;
// freq_entry->unused3 = 0;
// data_written += sizeof(struct FreqNfcEntry);
/* write the replay dict */
struct ReplayDictNfcWriterContext wr_ctx = {
.cur = dev_data->mf_ul_data.data + data_written,
.max = dev_data->mf_ul_data.data + NFC_MAX_BYTES};
// /* write the replay dict */
// struct ReplayDictNfcWriterContext wr_ctx = {
// .cur = dev_data->mf_ul_data.data + data_written,
// .max = dev_data->mf_ul_data.data + NFC_MAX_BYTES};
size_t n_entries =
crypto_ctx_dump_replay_dict(state->crypto_ctx, replay_dict_nfc_writer, &wr_ctx);
data_written += n_entries * sizeof(struct ReplayDictNfcEntry);
// size_t n_entries =
// crypto_ctx_dump_replay_dict(state->crypto_ctx, replay_dict_nfc_writer, &wr_ctx);
// data_written += n_entries * sizeof(struct ReplayDictNfcEntry);
/* calculate size of data, add 16 for config pages */
dev_data->mf_ul_data.data_size = data_written + (NFC_CONFIG_PAGES * 4);
}
// /* calculate size of data, add 16 for config pages */
// dev_data->mf_ul_data.data_size = data_written + (NFC_CONFIG_PAGES * 4);
// }
/* Prepares the key share popup scene. */
void scene_on_enter_key_share_popup(void* context) {
FURI_LOG_T(APPLICATION_NAME, "scene_on_enter_key_share_popup");
// /* Prepares the key share popup scene. */
// void scene_on_enter_key_share_popup(void* context) {
// FURI_LOG_T(APPLICATION_NAME, "scene_on_enter_key_share_popup");
furi_assert(context);
ESubGhzChatState* state = context;
// furi_assert(context);
// ESubGhzChatState* state = context;
popup_reset(state->nfc_popup);
// popup_reset(state->nfc_popup);
popup_disable_timeout(state->nfc_popup);
// popup_disable_timeout(state->nfc_popup);
popup_set_header(state->nfc_popup, "Sharing...", 67, 13, AlignLeft, AlignTop);
popup_set_icon(state->nfc_popup, 0, 3, &I_NFC_dolphin_emulation_47x61);
popup_set_text(state->nfc_popup, "Sharing\nKey via\nNFC", 90, 28, AlignCenter, AlignTop);
// popup_set_header(state->nfc_popup, "Sharing...", 67, 13, AlignLeft, AlignTop);
// popup_set_icon(state->nfc_popup, 0, 3, &I_NFC_dolphin_emulation_47x61);
// popup_set_text(state->nfc_popup, "Sharing\nKey via\nNFC", 90, 28, AlignCenter, AlignTop);
prepare_nfc_dev_data(state);
nfc_worker_start(
state->nfc_worker, NfcWorkerStateMfUltralightEmulate, state->nfc_dev_data, NULL, NULL);
// prepare_nfc_dev_data(state);
// nfc_worker_start(
// state->nfc_worker, NfcWorkerStateMfUltralightEmulate, state->nfc_dev_data, NULL, NULL);
notification_message(state->notification, &sequence_blink_start_magenta);
// notification_message(state->notification, &sequence_blink_start_magenta);
view_dispatcher_switch_to_view(state->view_dispatcher, ESubGhzChatView_NfcPopup);
}
// view_dispatcher_switch_to_view(state->view_dispatcher, ESubGhzChatView_NfcPopup);
// }
/* Handles scene manager events for the key share popup scene. */
bool scene_on_event_key_share_popup(void* context, SceneManagerEvent event) {
FURI_LOG_T(APPLICATION_NAME, "scene_on_event_key_share_popup");
// /* Handles scene manager events for the key share popup scene. */
// bool scene_on_event_key_share_popup(void* context, SceneManagerEvent event) {
// FURI_LOG_T(APPLICATION_NAME, "scene_on_event_key_share_popup");
furi_assert(context);
ESubGhzChatState* state = context;
// furi_assert(context);
// ESubGhzChatState* state = context;
UNUSED(state);
UNUSED(event);
// UNUSED(state);
// UNUSED(event);
return false;
}
// return false;
// }
/* Cleans up the key share popup scene. */
void scene_on_exit_key_share_popup(void* context) {
FURI_LOG_T(APPLICATION_NAME, "scene_on_exit_key_share_popup");
// /* Cleans up the key share popup scene. */
// void scene_on_exit_key_share_popup(void* context) {
// FURI_LOG_T(APPLICATION_NAME, "scene_on_exit_key_share_popup");
furi_assert(context);
ESubGhzChatState* state = context;
// furi_assert(context);
// ESubGhzChatState* state = context;
popup_reset(state->nfc_popup);
// popup_reset(state->nfc_popup);
notification_message(state->notification, &sequence_blink_stop);
// notification_message(state->notification, &sequence_blink_stop);
nfc_worker_stop(state->nfc_worker);
// nfc_worker_stop(state->nfc_worker);
crypto_explicit_bzero(state->nfc_dev_data->mf_ul_data.data, KEY_BITS / 8);
memset(state->nfc_dev_data, 0, sizeof(NfcDeviceData));
}
// crypto_explicit_bzero(state->nfc_dev_data->mf_ul_data.data, KEY_BITS / 8);
// memset(state->nfc_dev_data, 0, sizeof(NfcDeviceData));
// }

View File

@@ -2,8 +2,8 @@ ADD_SCENE(esubghz_chat, freq_input, FreqInput)
ADD_SCENE(esubghz_chat, key_menu, KeyMenu)
ADD_SCENE(esubghz_chat, pass_input, PassInput)
ADD_SCENE(esubghz_chat, hex_key_input, HexKeyInput)
ADD_SCENE(esubghz_chat, key_read_popup, KeyReadPopup)
// ADD_SCENE(esubghz_chat, key_read_popup, KeyReadPopup)
ADD_SCENE(esubghz_chat, chat_input, ChatInput)
ADD_SCENE(esubghz_chat, chat_box, ChatBox)
ADD_SCENE(esubghz_chat, key_display, KeyDisplay)
ADD_SCENE(esubghz_chat, key_share_popup, KeySharePopup)
// ADD_SCENE(esubghz_chat, key_share_popup, KeySharePopup)