mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-12 18:58:36 -07:00
NFC: slight FeliCa refactor
This commit is contained in:
@@ -39,11 +39,12 @@
|
||||
|
||||
#include "rpc/rpc_app.h"
|
||||
|
||||
#include <m-list.h>
|
||||
#include <m-array.h>
|
||||
|
||||
ARRAY_DEF(FelicaAreaPath, FelicaArea*, M_PTR_OPLIST);
|
||||
ARRAY_DEF(FuriStringStack, FuriString*, M_PTR_OPLIST);
|
||||
ARRAY_DEF(MfClassicUserKeys, char*, M_PTR_OPLIST);
|
||||
ARRAY_DEF(FelicaAreaPath, FelicaArea*, M_PTR_OPLIST)
|
||||
LIST_DEF(FuriStringStack, FuriString*, FURI_STRING_OPLIST)
|
||||
ARRAY_DEF(MfClassicUserKeys, char*, M_PTR_OPLIST)
|
||||
|
||||
#define NFC_TEXT_STORE_SIZE 128
|
||||
#define NFC_APP_FOLDER ANY_PATH("nfc")
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
#include "../nfc_i.h"
|
||||
#include <dolphin/dolphin.h>
|
||||
|
||||
#define SYSTEM_EVENT
|
||||
|
||||
void nfc_scene_felica_info_select_submenu_callback(void* context, uint32_t index) {
|
||||
Nfc* nfc = context;
|
||||
|
||||
@@ -20,7 +18,7 @@ void nfc_scene_felica_info_select_on_enter(void* context) {
|
||||
|
||||
submenu_add_item(submenu, "[Actions]", 0, nfc_scene_felica_info_select_submenu_callback, nfc);
|
||||
uint8_t i = 1;
|
||||
if(state->selected_system == NULL) {
|
||||
if(state->selected_system == NULL || state->selected_system->code == LITE_SYSTEM_CODE) {
|
||||
submenu_set_header(submenu, "Systems");
|
||||
FelicaSystemList_it_t it;
|
||||
for(FelicaSystemList_it(it, data->systems); !FelicaSystemList_end_p(it);
|
||||
@@ -59,8 +57,7 @@ void nfc_scene_felica_info_select_on_enter(void* context) {
|
||||
FelicaNodeList_next(it)) {
|
||||
FelicaNode* node = *FelicaNodeList_ref(it);
|
||||
if(node->type == FelicaNodeTypeArea) {
|
||||
FuriString* area_name =
|
||||
furi_string_alloc_printf("Area %d", node->ptr.area->number);
|
||||
FuriString* area_name = furi_string_alloc_printf("Area %d", node->area->number);
|
||||
submenu_add_item(
|
||||
submenu,
|
||||
furi_string_get_cstr(area_name),
|
||||
@@ -69,7 +66,7 @@ void nfc_scene_felica_info_select_on_enter(void* context) {
|
||||
nfc);
|
||||
FuriStringStack_push_back(state->strings, area_name);
|
||||
} else {
|
||||
uint16_t service_code = node->ptr.service->number << 6;
|
||||
uint16_t service_code = node->service->number << 6;
|
||||
FuriString* service_name = furi_string_alloc_printf("Service %04X", service_code);
|
||||
submenu_add_item(
|
||||
submenu,
|
||||
@@ -106,7 +103,11 @@ bool nfc_scene_felica_info_select_on_event(void* context, SceneManagerEvent even
|
||||
index -= 1;
|
||||
if(state->selected_system == NULL) {
|
||||
state->selected_system = *FelicaSystemList_get(data->systems, index);
|
||||
scene_manager_next_scene(nfc->scene_manager, NfcSceneFelicaInfoSelect);
|
||||
if(state->selected_system->code == LITE_SYSTEM_CODE) {
|
||||
scene_manager_next_scene(nfc->scene_manager, NfcSceneFelicaServiceData);
|
||||
} else {
|
||||
scene_manager_next_scene(nfc->scene_manager, NfcSceneFelicaInfoSelect);
|
||||
}
|
||||
consumed = true;
|
||||
} else {
|
||||
FelicaNode* selected_node = NULL;
|
||||
@@ -119,11 +120,11 @@ bool nfc_scene_felica_info_select_on_event(void* context, SceneManagerEvent even
|
||||
}
|
||||
|
||||
if(selected_node->type == FelicaNodeTypeArea) {
|
||||
FelicaAreaPath_push_back(state->selected_areas, selected_node->ptr.area);
|
||||
FelicaAreaPath_push_back(state->selected_areas, selected_node->area);
|
||||
scene_manager_next_scene(nfc->scene_manager, NfcSceneFelicaInfoSelect);
|
||||
consumed = true;
|
||||
} else if(selected_node->type == FelicaNodeTypeService) {
|
||||
state->selected_service = selected_node->ptr.service;
|
||||
state->selected_service = selected_node->service;
|
||||
scene_manager_next_scene(nfc->scene_manager, NfcSceneFelicaServiceData);
|
||||
consumed = true;
|
||||
}
|
||||
@@ -146,10 +147,6 @@ void nfc_scene_felica_info_select_on_exit(void* context) {
|
||||
|
||||
// Clear view
|
||||
FelicaAreaPath_clear(nfc->felica_select.selected_areas);
|
||||
FuriStringStack_it_t it;
|
||||
for(FuriStringStack_it(it, nfc->felica_select.strings); !FuriStringStack_end_p(it);
|
||||
FuriStringStack_next(it)) {
|
||||
furi_string_free(*FuriStringStack_ref(it));
|
||||
}
|
||||
FuriStringStack_clear(nfc->felica_select.strings);
|
||||
submenu_reset(nfc->submenu);
|
||||
}
|
||||
|
||||
@@ -4,21 +4,22 @@ void nfc_scene_felica_service_data_on_enter(void* context) {
|
||||
Nfc* nfc = context;
|
||||
FelicaSelectState* select_state = &nfc->felica_select;
|
||||
FelicaSystem* system = select_state->selected_system;
|
||||
FelicaService* service = select_state->selected_service;
|
||||
//FelicaService* service = select_state->selected_service;
|
||||
TextBox* text_box = nfc->text_box;
|
||||
|
||||
if(system->code == LITE_SYSTEM_CODE && service->number == 0) {
|
||||
if(system->code == LITE_SYSTEM_CODE) {
|
||||
FelicaLiteInfo* lite_info = &system->lite_info;
|
||||
uint8_t* data;
|
||||
text_box_set_font(text_box, TextBoxFontHex);
|
||||
furi_string_cat_str(nfc->text_box_store, "S_PAD:\n");
|
||||
for(int i = 0; i < REG_LITE_BLOCK; i++) {
|
||||
FelicaBlock* block = *FelicaBlockList_cget(service->blocks, i);
|
||||
data = lite_info->S_PAD[i];
|
||||
for(uint16_t i = 0; i < FELICA_BLOCK_SIZE; i += 2) {
|
||||
if(!(i % 8) && i) {
|
||||
furi_string_push_back(nfc->text_box_store, '\n');
|
||||
}
|
||||
if(block != NULL) {
|
||||
furi_string_cat_printf(
|
||||
nfc->text_box_store, "%02X%02X ", block->data[i], block->data[i + 1]);
|
||||
if(data != NULL) {
|
||||
furi_string_cat_printf(nfc->text_box_store, "%02X%02X ", data[i], data[i + 1]);
|
||||
} else {
|
||||
furi_string_cat_printf(nfc->text_box_store, "???? ");
|
||||
}
|
||||
@@ -26,107 +27,56 @@ void nfc_scene_felica_service_data_on_enter(void* context) {
|
||||
}
|
||||
|
||||
furi_string_cat_str(nfc->text_box_store, "REG:\n");
|
||||
FelicaBlock* block = *FelicaBlockList_cget(service->blocks, REG_LITE_BLOCK);
|
||||
data = lite_info->REG;
|
||||
for(uint16_t i = 0; i < FELICA_BLOCK_SIZE; i += 2) {
|
||||
if(!(i % 8) && i) {
|
||||
furi_string_push_back(nfc->text_box_store, '\n');
|
||||
}
|
||||
if(block != NULL) {
|
||||
furi_string_cat_printf(
|
||||
nfc->text_box_store, "%02X%02X ", block->data[i], block->data[i + 1]);
|
||||
if(data != NULL) {
|
||||
furi_string_cat_printf(nfc->text_box_store, "%02X%02X ", data[i], data[i + 1]);
|
||||
} else {
|
||||
furi_string_cat_printf(nfc->text_box_store, "???? ");
|
||||
}
|
||||
}
|
||||
|
||||
furi_string_cat_str(nfc->text_box_store, "RC:\n");
|
||||
block = *FelicaBlockList_cget(service->blocks, RC_LITE_BLOCK);
|
||||
for(uint16_t i = 0; i < FELICA_BLOCK_SIZE; i += 2) {
|
||||
if(!(i % 8) && i) {
|
||||
furi_string_push_back(nfc->text_box_store, '\n');
|
||||
}
|
||||
furi_string_cat_printf(
|
||||
nfc->text_box_store, "%02X%02X ", block->data[i], block->data[i + 1]);
|
||||
}
|
||||
|
||||
furi_string_cat_str(nfc->text_box_store, "MAC:\n");
|
||||
block = *FelicaBlockList_cget(service->blocks, MAC_LITE_BLOCK);
|
||||
for(uint16_t i = 0; i < FELICA_BLOCK_SIZE; i += 2) {
|
||||
data = lite_info->MAC;
|
||||
for(uint16_t i = 0; i < 8; i += 2) {
|
||||
if(!(i % 8) && i) {
|
||||
furi_string_push_back(nfc->text_box_store, '\n');
|
||||
}
|
||||
furi_string_cat_printf(
|
||||
nfc->text_box_store, "%02X%02X ", block->data[i], block->data[i + 1]);
|
||||
furi_string_cat_printf(nfc->text_box_store, "%02X%02X ", data[i], data[i + 1]);
|
||||
}
|
||||
|
||||
furi_string_cat_str(nfc->text_box_store, "ID:\n");
|
||||
block = *FelicaBlockList_cget(service->blocks, ID_LITE_BLOCK);
|
||||
for(uint16_t i = 0; i < FELICA_BLOCK_SIZE; i += 2) {
|
||||
if(!(i % 8) && i) {
|
||||
furi_string_push_back(nfc->text_box_store, '\n');
|
||||
}
|
||||
furi_string_cat_printf(
|
||||
nfc->text_box_store, "%02X%02X ", block->data[i], block->data[i + 1]);
|
||||
}
|
||||
furi_string_cat_printf(nfc->text_box_store, "DFC: %04X\n", lite_info->data_format_code);
|
||||
|
||||
furi_string_cat_str(nfc->text_box_store, "D_ID:\n");
|
||||
block = *FelicaBlockList_cget(service->blocks, DEVICE_ID_LITE_BLOCK);
|
||||
for(uint16_t i = 0; i < FELICA_BLOCK_SIZE; i += 2) {
|
||||
if(!(i % 8) && i) {
|
||||
furi_string_push_back(nfc->text_box_store, '\n');
|
||||
}
|
||||
furi_string_cat_printf(
|
||||
nfc->text_box_store, "%02X%02X ", block->data[i], block->data[i + 1]);
|
||||
furi_string_cat_str(nfc->text_box_store, "ID data:\n");
|
||||
data = lite_info->ID_value;
|
||||
for(uint16_t i = 0; i < 6; i += 2) {
|
||||
furi_string_cat_printf(nfc->text_box_store, "%02X%02X ", data[i], data[i + 1]);
|
||||
}
|
||||
furi_string_cat_str(nfc->text_box_store, "\n");
|
||||
|
||||
furi_string_cat_str(nfc->text_box_store, "CKV:\n");
|
||||
block = *FelicaBlockList_cget(service->blocks, CARD_KEY_VER_LITE_BLOCK);
|
||||
for(uint16_t i = 0; i < FELICA_BLOCK_SIZE; i += 2) {
|
||||
if(!(i % 8) && i) {
|
||||
furi_string_push_back(nfc->text_box_store, '\n');
|
||||
}
|
||||
furi_string_cat_printf(
|
||||
nfc->text_box_store, "%02X%02X ", block->data[i], block->data[i + 1]);
|
||||
}
|
||||
furi_string_cat_printf(nfc->text_box_store, "CKV: %04X\n", lite_info->card_key_version);
|
||||
|
||||
furi_string_cat_str(nfc->text_box_store, "MC:\n");
|
||||
block = *FelicaBlockList_cget(service->blocks, MEM_CONFIG_LITE_BLOCK);
|
||||
data = lite_info->memory_config;
|
||||
for(uint16_t i = 0; i < FELICA_BLOCK_SIZE; i += 2) {
|
||||
if(!(i % 8) && i) {
|
||||
furi_string_push_back(nfc->text_box_store, '\n');
|
||||
}
|
||||
furi_string_cat_printf(
|
||||
nfc->text_box_store, "%02X%02X ", block->data[i], block->data[i + 1]);
|
||||
furi_string_cat_printf(nfc->text_box_store, "%02X%02X ", data[i], data[i + 1]);
|
||||
}
|
||||
|
||||
furi_string_cat_str(nfc->text_box_store, "WCNT:\n");
|
||||
block = *FelicaBlockList_cget(service->blocks, WRITE_COUNT_LITE_BLOCK);
|
||||
for(uint16_t i = 0; i < FELICA_BLOCK_SIZE; i += 2) {
|
||||
if(!(i % 8) && i) {
|
||||
furi_string_push_back(nfc->text_box_store, '\n');
|
||||
}
|
||||
furi_string_cat_printf(
|
||||
nfc->text_box_store, "%02X%02X ", block->data[i], block->data[i + 1]);
|
||||
}
|
||||
furi_string_cat_printf(nfc->text_box_store, "WCNT: %06lX\n", lite_info->write_count);
|
||||
|
||||
furi_string_cat_str(nfc->text_box_store, "MAC_A:\n");
|
||||
block = *FelicaBlockList_cget(service->blocks, MAC_A_LITE_BLOCK);
|
||||
for(uint16_t i = 0; i < FELICA_BLOCK_SIZE; i += 2) {
|
||||
data = lite_info->MAC_A;
|
||||
for(uint16_t i = 0; i < 8; i += 2) {
|
||||
if(!(i % 8) && i) {
|
||||
furi_string_push_back(nfc->text_box_store, '\n');
|
||||
}
|
||||
furi_string_cat_printf(
|
||||
nfc->text_box_store, "%02X%02X ", block->data[i], block->data[i + 1]);
|
||||
}
|
||||
|
||||
furi_string_cat_str(nfc->text_box_store, "CRC_CHECK:\n");
|
||||
block = *FelicaBlockList_cget(service->blocks, CRC_CHECK_LITE_BLOCK);
|
||||
for(uint16_t i = 0; i < FELICA_BLOCK_SIZE; i += 2) {
|
||||
if(!(i % 8) && i) {
|
||||
furi_string_push_back(nfc->text_box_store, '\n');
|
||||
}
|
||||
furi_string_cat_printf(
|
||||
nfc->text_box_store, "%02X%02X ", block->data[i], block->data[i + 1]);
|
||||
furi_string_cat_printf(nfc->text_box_store, "%02X%02X ", data[i], data[i + 1]);
|
||||
}
|
||||
}
|
||||
text_box_set_text(text_box, furi_string_get_cstr(nfc->text_box_store));
|
||||
|
||||
Reference in New Issue
Block a user