Merge branch 'dev' into release
74
CHANGELOG.md
@@ -1,42 +1,40 @@
|
|||||||
### New changes
|
### New changes
|
||||||
* **Warning! After installing, Desktop settings (Favoutite apps, PIN Code, AutoLock time..) will be resetted to default due to OFW changes, Please set your PIN code, Favourite apps again in Settings->Desktop**
|
* !!! **Warning! After installing, Desktop settings (Favoutite apps, PIN Code, AutoLock time..) will be resetted to default due to settings changes, Please set your PIN code, Favourite apps again in Settings->Desktop** !!!
|
||||||
* New way of changing device name -> **Now can be changed in Settings->Desktop** (by @xMasterX and @Willy-JL)
|
* If you have copied any apps manually into `apps` folder - remove `apps` folder or that specific apps you copied on your microSD before installing this release to avoid issues due to OFW API version update! If you using regular builds or extra pack builds (e) without your manually added apps, all included apps will be installed automatically, no extra actions needed!
|
||||||
* Plugins: BadBT plugin (BT version of BadKB) [(by Willy-JL, ClaraCrazy, XFW contributors)](https://github.com/ClaraCrazy/Flipper-Xtreme/tree/dev/applications/main/bad_kb)
|
-----
|
||||||
* Plugins: WiFi Marauder -> Added sniff pmkid on selected aps from 0.10.4 update (by @clipboard1)
|
* Desktop: **Show clock on main screen** (Enable in Settings->Desktop->Show Clock) (by @gid9798 | PR #484)
|
||||||
* Plugins: SubGHz Bruteforcer -> Increase delay just a little bit to fix some cases when receiver will not get codes and decrease manual transmit delay
|
* SubGHz Remote: New plugin - Configurator (Remote Maker) - Now you can create and edit map files on flipper! (by @gid9798 | PR #487)
|
||||||
* Plugins: UART Terminal -> Fix crashes on plugin load with RX connected
|
* SubGHz Remote: Full refactoring, app was re-made from scratch (by @gid9798)
|
||||||
* NFC: Mifare mini with SAK 0x89 support
|
* Archive: Fix rename, show error message to user
|
||||||
* SubGHz: **CAME Atomo - Add manually support and custom buttons support**
|
* API: Cleanup, mini refactoring of some apps (+6k of free flash space)
|
||||||
* SubGHz: Fix crashes when deleting signals using right arrow button in `Read` mode
|
* LFRFID: Debug: Allow PSK RAW emulation in gui
|
||||||
* SubGHz: Restore Rx indication after deletion after Memory is FULL (by @wosk | PR #464)
|
* SubGHz: Security+ 2.0 -> add extra custom button `0x78` - Fixes issue #469
|
||||||
* SubGHz: **App refactoring** (OFW code ported + our code was refactored/cleaned up too) (by @gid9798 and @xMasterX | PR #461)
|
* SubGHz: Various fixes (by @gid9798)
|
||||||
* SubGHz: Using scene manager functions in DecodeRAW (by @gid9798 | PR #462)
|
* SubGHz: Fix counter settings in debug
|
||||||
* SubGHz: Protocols and custom buttons refactoring (by @gid9798 | PR #465)
|
* SubGHz: Move dangerous_settings check (by @gid9798 | PR #475)
|
||||||
* SubGHz: Move `counter increase` setting out of debug, change max value
|
* Misc: Move NFC plugins into NFC folder
|
||||||
* GUI: Submenu locked elements (by @Willy-JL and @giacomoferretti)
|
* Misc: Name changer code moved to proper place, load after system startup + extra checks
|
||||||
* GUI: Text Input improvements, added cursor and ability to set minimal length (by @Willy-JL)
|
* Plugins: Merge tiktok and ytshorts remote into one (by @Willy-JL)
|
||||||
* BT API: Functions that allow to change bt mac address and device broadcasted name (by @Willy-JL and XFW contributors)
|
* Plugins: NMEA GPS UART - stability fix
|
||||||
* Infrared: `External output` move out of debug and add power option for external modules
|
* Plugins: Port XFW keyboard with extra symbols to WiFi Marauder instead of using UART Term keyboard (thanks to @Willy-JL)
|
||||||
* Infrared: Updated universal remote assets (by @amec0e | PR #474)
|
* Plugins: Moved from extra pack to main FW: Mifare Nested [(by AloneLiberty)](https://github.com/AloneLiberty/FlipperNested) - Works with PC and python app `FlipperNested`
|
||||||
* Extra pack: Some app fixes
|
* Plugins: Update TOTP (Authenticator) [(by akopachov)](https://github.com/akopachov/flipper-zero_authenticator) (+ Add option to set custom fonts)
|
||||||
* FBT: Fix vscode example config for debug builds - please run `./fbt vscode_dist` again if you had issues with debug builds size
|
* Plugins: Update NMEA GPS UART [(by ezod)](https://github.com/ezod/flipperzero-gps) (GLL support)
|
||||||
* OFW PR 2316: NFC V support (by @g3gg0 & @nvx)
|
* Plugins: Update WiFi Marauder [(by 0xchocolate)](https://github.com/0xchocolate/flipperzero-firmware-with-wifi-marauder-companion)
|
||||||
* OFW PR 2669: nfc: Fix MFUL tearing flags read (by @GMMan)
|
* OFW PR 2680: RFID - Add support for Nexkey/Nexwatch (by @mauimauer)
|
||||||
* OFW PR 2666: BadUSB: Add fr-FR-mac key layout (by @FelixLgr)
|
* OFW: nfc: Mifare Ultralight C detection
|
||||||
* OFW: api: added lib/nfc/protocols/nfc_util.h
|
* OFW: api: added toolbox/api_lock.h
|
||||||
* OFW: fix PIN retry count reset on reboot
|
* OFW: NFC: Add support for Gen4 "ultimate card" in Magic app
|
||||||
* OFW: fbt: allow strings for fap_version field in app manifests
|
* OFW: desktop: Refactor favorites settings and allow app browser in selection
|
||||||
* OFW: Rpc: add desktop service. Desktop: refactor locking routine. **Now PIN lock is actually cannot be bypassed by reboot!** / **Desktop settings will be reset, please set your PIN and favourite apps again!**
|
* OFW: Infrared: respect carrier frequency and duty cycle settings -> **Breaking API change, API version was changed from 26.x to 27.x**
|
||||||
* OFW: Part 2 of hooking C2 IPC
|
* OFW: Desktop,Rpc: desktop status subscription
|
||||||
* OFW: ble: attempt to handle hardfaulted c2
|
* OFW: Storage, common_rename: check that old path is exists
|
||||||
* OFW: Add Mfkey32 application
|
* OFW: Services: remove deallocator for persistent services
|
||||||
* OFW: Added DigitalSequence and PulseReader
|
* OFW: Storage: common_rename is now POSIX compliant
|
||||||
* OFW: Debug: revert cortex debug to lxml and drop DWT **(reapply your VSCode launch.json from example folder)**
|
* OFW: Removed user-specific data from tar artifacts
|
||||||
* OFW: furi_crash: added C2 status; added fw-version gdb command
|
* OFW: fbt: Fix tar uid overflow when packaging
|
||||||
* OFW: Removed STM32CubeWB module
|
* OFW: fbt: Use union for old py (Fix builds if using older python versions)
|
||||||
* OFW: API version in UI
|
* OFW: USB HID report timeout
|
||||||
* OFW: ufbt: deploying sample ufbt automation for new apps; added `source "ufbt -s env"` for toolchain access
|
|
||||||
* OFW: Fix storage.py exist_dir logic
|
|
||||||
|
|
||||||
#### [🎲 Download latest extra apps pack](https://github.com/xMasterX/all-the-plugins/archive/refs/heads/main.zip)
|
#### [🎲 Download latest extra apps pack](https://github.com/xMasterX/all-the-plugins/archive/refs/heads/main.zip)
|
||||||
|
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ Our Discord Community:
|
|||||||
* Universal remote for Projectors, Fans, A/Cs and Audio(soundbars, etc.)
|
* Universal remote for Projectors, Fans, A/Cs and Audio(soundbars, etc.)
|
||||||
* Customizable Flipper name **Update! Now can be changed in Settings->Desktop** (by @xMasterX and @Willy-JL)
|
* Customizable Flipper name **Update! Now can be changed in Settings->Desktop** (by @xMasterX and @Willy-JL)
|
||||||
* Text Input UI element -> Cursor feature (by @Willy-JL)
|
* Text Input UI element -> Cursor feature (by @Willy-JL)
|
||||||
|
- **BadBT** plugin (BT version of BadKB) [(by Willy-JL, ClaraCrazy, XFW contributors)](https://github.com/ClaraCrazy/Flipper-Xtreme/tree/dev/applications/main/bad_kb) - (See in Applications->Tools) - (aka BadUSB via Bluetooth)
|
||||||
- BadUSB -> Keyboard layouts [(by rien > dummy-decoy)](https://github.com/dummy-decoy/flipperzero-firmware/tree/dummy_decoy/bad_usb_keyboard_layout)
|
- BadUSB -> Keyboard layouts [(by rien > dummy-decoy)](https://github.com/dummy-decoy/flipperzero-firmware/tree/dummy_decoy/bad_usb_keyboard_layout)
|
||||||
- Sub-GHz -> External CC1101 module support - [(by quen0n)](https://github.com/DarkFlippers/unleashed-firmware/pull/307)
|
- Sub-GHz -> External CC1101 module support - [(by quen0n)](https://github.com/DarkFlippers/unleashed-firmware/pull/307)
|
||||||
- Sub-GHz -> `Add manually` menu extended with new protocols
|
- Sub-GHz -> `Add manually` menu extended with new protocols
|
||||||
@@ -145,7 +146,7 @@ You can support us by using links or addresses below:
|
|||||||
- ESP32: WiFi Marauder companion plugin [(by 0xchocolate)](https://github.com/0xchocolate/flipperzero-firmware-with-wifi-marauder-companion) - Saving .pcap on flipper microSD [by tcpassos](https://github.com/tcpassos/flipperzero-firmware-with-wifi-marauder-companion) -> Only with custom marauder build (It is necessary to uncomment "#define WRITE_PACKETS_SERIAL" in configs.h (in marauder fw) and compile the firmware for the wifi board.) Or download precompiled build -> [Download esp32_marauder_ver_flipper_sd_serial.bin](https://github.com/justcallmekoko/ESP32Marauder/releases/latest)
|
- ESP32: WiFi Marauder companion plugin [(by 0xchocolate)](https://github.com/0xchocolate/flipperzero-firmware-with-wifi-marauder-companion) - Saving .pcap on flipper microSD [by tcpassos](https://github.com/tcpassos/flipperzero-firmware-with-wifi-marauder-companion) -> Only with custom marauder build (It is necessary to uncomment "#define WRITE_PACKETS_SERIAL" in configs.h (in marauder fw) and compile the firmware for the wifi board.) Or download precompiled build -> [Download esp32_marauder_ver_flipper_sd_serial.bin](https://github.com/justcallmekoko/ESP32Marauder/releases/latest)
|
||||||
- NRF24: Sniffer & MouseJacker (with changes) [(by mothball187)](https://github.com/mothball187/flipperzero-nrf24/tree/main/mousejacker)
|
- NRF24: Sniffer & MouseJacker (with changes) [(by mothball187)](https://github.com/mothball187/flipperzero-nrf24/tree/main/mousejacker)
|
||||||
- Simple Clock (timer by GMMan) [(original by CompaqDisc)](https://gist.github.com/CompaqDisc/4e329c501bd03c1e801849b81f48ea61)
|
- Simple Clock (timer by GMMan) [(original by CompaqDisc)](https://gist.github.com/CompaqDisc/4e329c501bd03c1e801849b81f48ea61)
|
||||||
- **Sub-GHz Remote** (UniversalRF Remix) [(by @darmiel & @xMasterX)](https://github.com/darmiel/flipper-playlist/tree/feat/unirf-protocols) (original by @ESurge)
|
- **Sub-GHz Remote** [(by @gid9798)](https://github.com/gid9798)
|
||||||
- Spectrum Analyzer (with changes) [(by jolcese)](https://github.com/jolcese/flipperzero-firmware/tree/spectrum/applications/spectrum_analyzer) - [Ultra Narrow mode & scan channels non-consecutively](https://github.com/theY4Kman/flipperzero-firmware/commits?author=theY4Kman)
|
- Spectrum Analyzer (with changes) [(by jolcese)](https://github.com/jolcese/flipperzero-firmware/tree/spectrum/applications/spectrum_analyzer) - [Ultra Narrow mode & scan channels non-consecutively](https://github.com/theY4Kman/flipperzero-firmware/commits?author=theY4Kman)
|
||||||
- Metronome [(by panki27)](https://github.com/panki27/Metronome)
|
- Metronome [(by panki27)](https://github.com/panki27/Metronome)
|
||||||
- DTMF Dolphin [(by litui)](https://github.com/litui/dtmf_dolphin)
|
- DTMF Dolphin [(by litui)](https://github.com/litui/dtmf_dolphin)
|
||||||
@@ -164,7 +165,8 @@ You can support us by using links or addresses below:
|
|||||||
- **ProtoView** [(by antirez)](https://github.com/antirez/protoview)
|
- **ProtoView** [(by antirez)](https://github.com/antirez/protoview)
|
||||||
- **SWD Probe** [(by g3gg0)](https://github.com/g3gg0/flipper-swd_probe)
|
- **SWD Probe** [(by g3gg0)](https://github.com/g3gg0/flipper-swd_probe)
|
||||||
- IR Scope [(by kallanreed)](https://github.com/DarkFlippers/unleashed-firmware/pull/407)
|
- IR Scope [(by kallanreed)](https://github.com/DarkFlippers/unleashed-firmware/pull/407)
|
||||||
- BadBT plugin (BT version of BadKB) [(by Willy-JL, ClaraCrazy, XFW contributors)](https://github.com/ClaraCrazy/Flipper-Xtreme/tree/dev/applications/main/bad_kb)
|
- **BadBT** plugin (BT version of BadKB) [(by Willy-JL, ClaraCrazy, XFW contributors)](https://github.com/ClaraCrazy/Flipper-Xtreme/tree/dev/applications/main/bad_kb) (See in Applications->Tools) - (aka BadUSB via Bluetooth)
|
||||||
|
- **Mifare Nested** [(by AloneLiberty)](https://github.com/AloneLiberty/FlipperNested) - Works with PC and python app `FlipperNested`
|
||||||
|
|
||||||
Games:
|
Games:
|
||||||
- DOOM (fixed) [(by p4nic4ttack)](https://github.com/p4nic4ttack/doom-flipper-zero/)
|
- DOOM (fixed) [(by p4nic4ttack)](https://github.com/p4nic4ttack/doom-flipper-zero/)
|
||||||
@@ -193,6 +195,8 @@ Games:
|
|||||||
|
|
||||||
## [- How to change Flipper name](https://github.com/DarkFlippers/unleashed-firmware/blob/dev/documentation/CustomFlipperName.md)
|
## [- How to change Flipper name](https://github.com/DarkFlippers/unleashed-firmware/blob/dev/documentation/CustomFlipperName.md)
|
||||||
|
|
||||||
|
## [- How to use Mifare Nested plugin to recover keys](https://github.com/AloneLiberty/FlipperNested#how-to-use-it)
|
||||||
|
|
||||||
### **Sub-GHz**
|
### **Sub-GHz**
|
||||||
|
|
||||||
## [- Transmission is blocked? - How to extend Sub-GHz frequency range](https://github.com/DarkFlippers/unleashed-firmware/blob/dev/documentation/DangerousSettings.md)
|
## [- Transmission is blocked? - How to extend Sub-GHz frequency range](https://github.com/DarkFlippers/unleashed-firmware/blob/dev/documentation/DangerousSettings.md)
|
||||||
|
|||||||
2
applications/external/doom/display.h
vendored
@@ -90,7 +90,7 @@ void drawVLine(uint8_t x, int8_t start_y, int8_t end_y, uint8_t intensity, Canva
|
|||||||
|
|
||||||
void setupDisplay(Canvas* canvas) {
|
void setupDisplay(Canvas* canvas) {
|
||||||
memset(zbuffer, 0xff, 128);
|
memset(zbuffer, 0xff, 128);
|
||||||
display_buf = (uint8_t*)canvas_get_buffer(canvas);
|
display_buf = (uint8_t*)canvas->fb.tile_buf_ptr;
|
||||||
//display_buf = u8g2_GetBufferPtr(&canvas->fb);
|
//display_buf = u8g2_GetBufferPtr(&canvas->fb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,8 +11,6 @@
|
|||||||
//#include <notification/notification_messages.h>
|
//#include <notification/notification_messages.h>
|
||||||
//#include <stdlib.h>
|
//#include <stdlib.h>
|
||||||
|
|
||||||
#include <u8g2.h>
|
|
||||||
|
|
||||||
#include "FlipperZeroWiFiDeauthModuleDefines.h"
|
#include "FlipperZeroWiFiDeauthModuleDefines.h"
|
||||||
|
|
||||||
#define DEAUTH_APP_DEBUG 0
|
#define DEAUTH_APP_DEBUG 0
|
||||||
@@ -154,10 +152,8 @@ static void esp8266_deauth_module_render_callback(Canvas* const canvas, void* ct
|
|||||||
const char* strInitializing = "Something wrong";
|
const char* strInitializing = "Something wrong";
|
||||||
canvas_draw_str(
|
canvas_draw_str(
|
||||||
canvas,
|
canvas,
|
||||||
(u8g2_GetDisplayWidth(&canvas->fb) / 2) -
|
(128 / 2) - (canvas_string_width(canvas, strInitializing) / 2),
|
||||||
(canvas_string_width(canvas, strInitializing) / 2),
|
(64 / 2) /* - (canvas_current_font_height(canvas) / 2)*/,
|
||||||
(u8g2_GetDisplayHeight(&canvas->fb) /
|
|
||||||
2) /* - (u8g2_GetMaxCharHeight(&canvas->fb) / 2)*/,
|
|
||||||
strInitializing);
|
strInitializing);
|
||||||
} break;
|
} break;
|
||||||
case WaitingForModule:
|
case WaitingForModule:
|
||||||
@@ -170,10 +166,8 @@ static void esp8266_deauth_module_render_callback(Canvas* const canvas, void* ct
|
|||||||
const char* strInitializing = "Attach WiFi Deauther module";
|
const char* strInitializing = "Attach WiFi Deauther module";
|
||||||
canvas_draw_str(
|
canvas_draw_str(
|
||||||
canvas,
|
canvas,
|
||||||
(u8g2_GetDisplayWidth(&canvas->fb) / 2) -
|
(128 / 2) - (canvas_string_width(canvas, strInitializing) / 2),
|
||||||
(canvas_string_width(canvas, strInitializing) / 2),
|
(64 / 2) /* - (canvas_current_font_height(canvas) / 2)*/,
|
||||||
(u8g2_GetDisplayHeight(&canvas->fb) /
|
|
||||||
2) /* - (u8g2_GetMaxCharHeight(&canvas->fb) / 2)*/,
|
|
||||||
strInitializing);
|
strInitializing);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -188,18 +182,16 @@ static void esp8266_deauth_module_render_callback(Canvas* const canvas, void* ct
|
|||||||
const char* strInitializing = "Initializing...";
|
const char* strInitializing = "Initializing...";
|
||||||
canvas_draw_str(
|
canvas_draw_str(
|
||||||
canvas,
|
canvas,
|
||||||
(u8g2_GetDisplayWidth(&canvas->fb) / 2) -
|
(128 / 2) - (canvas_string_width(canvas, strInitializing) / 2),
|
||||||
(canvas_string_width(canvas, strInitializing) / 2),
|
(64 / 2) - (canvas_current_font_height(canvas) / 2),
|
||||||
(u8g2_GetDisplayHeight(&canvas->fb) / 2) -
|
|
||||||
(u8g2_GetMaxCharHeight(&canvas->fb) / 2),
|
|
||||||
strInitializing);
|
strInitializing);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif // ENABLE_MODULE_POWER
|
#endif // ENABLE_MODULE_POWER
|
||||||
break;
|
break;
|
||||||
case ModuleActive: {
|
case ModuleActive: {
|
||||||
uint8_t* buffer = canvas_get_buffer(canvas);
|
uint8_t* buffer = canvas->fb.tile_buf_ptr;
|
||||||
app->m_canvasSize = canvas_get_buffer_size(canvas);
|
app->m_canvasSize = gui_get_framebuffer_size(app->m_gui);
|
||||||
memcpy(buffer, app->m_backBuffer, app->m_canvasSize);
|
memcpy(buffer, app->m_backBuffer, app->m_canvasSize);
|
||||||
} break;
|
} break;
|
||||||
default:
|
default:
|
||||||
|
|||||||
48
applications/external/gps_nmea_uart/gps_uart.c
vendored
@@ -66,6 +66,19 @@ static void gps_uart_parse_nmea(GpsUart* gps_uart, char* line) {
|
|||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
|
case MINMEA_SENTENCE_GLL: {
|
||||||
|
struct minmea_sentence_gll frame;
|
||||||
|
if(minmea_parse_gll(&frame, line)) {
|
||||||
|
gps_uart->status.latitude = minmea_tocoord(&frame.latitude);
|
||||||
|
gps_uart->status.longitude = minmea_tocoord(&frame.longitude);
|
||||||
|
gps_uart->status.time_hours = frame.time.hours;
|
||||||
|
gps_uart->status.time_minutes = frame.time.minutes;
|
||||||
|
gps_uart->status.time_seconds = frame.time.seconds;
|
||||||
|
|
||||||
|
notification_message_block(gps_uart->notifications, &sequence_blink_red_10);
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -74,11 +87,8 @@ static void gps_uart_parse_nmea(GpsUart* gps_uart, char* line) {
|
|||||||
static int32_t gps_uart_worker(void* context) {
|
static int32_t gps_uart_worker(void* context) {
|
||||||
GpsUart* gps_uart = (GpsUart*)context;
|
GpsUart* gps_uart = (GpsUart*)context;
|
||||||
|
|
||||||
gps_uart->rx_stream = furi_stream_buffer_alloc(RX_BUF_SIZE * 5, 1);
|
|
||||||
size_t rx_offset = 0;
|
size_t rx_offset = 0;
|
||||||
|
|
||||||
gps_uart_serial_init(gps_uart);
|
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
uint32_t events =
|
uint32_t events =
|
||||||
furi_thread_flags_wait(WORKER_ALL_RX_EVENTS, FuriFlagWaitAny, FuriWaitForever);
|
furi_thread_flags_wait(WORKER_ALL_RX_EVENTS, FuriFlagWaitAny, FuriWaitForever);
|
||||||
@@ -91,35 +101,53 @@ static int32_t gps_uart_worker(void* context) {
|
|||||||
if(events & WorkerEvtRxDone) {
|
if(events & WorkerEvtRxDone) {
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
do {
|
do {
|
||||||
|
// receive serial bytes into rx_buf, starting at rx_offset from the start of the buffer
|
||||||
|
// the maximum we can receive is RX_BUF_SIZE - 1 - rx_offset
|
||||||
len = furi_stream_buffer_receive(
|
len = furi_stream_buffer_receive(
|
||||||
gps_uart->rx_stream,
|
gps_uart->rx_stream,
|
||||||
gps_uart->rx_buf + rx_offset,
|
gps_uart->rx_buf + rx_offset,
|
||||||
RX_BUF_SIZE - 1 - rx_offset,
|
RX_BUF_SIZE - 1 - rx_offset,
|
||||||
0);
|
0);
|
||||||
if(len > 0) {
|
if(len > 0) {
|
||||||
|
// increase rx_offset by the number of bytes received, and null-terminate rx_buf
|
||||||
rx_offset += len;
|
rx_offset += len;
|
||||||
gps_uart->rx_buf[rx_offset] = '\0';
|
gps_uart->rx_buf[rx_offset] = '\0';
|
||||||
|
|
||||||
|
// look for strings ending in newlines, starting at the start of rx_buf
|
||||||
char* line_current = (char*)gps_uart->rx_buf;
|
char* line_current = (char*)gps_uart->rx_buf;
|
||||||
while(1) {
|
while(1) {
|
||||||
|
// skip null characters
|
||||||
while(*line_current == '\0' &&
|
while(*line_current == '\0' &&
|
||||||
line_current < (char*)gps_uart->rx_buf + rx_offset - 1) {
|
line_current < (char*)gps_uart->rx_buf + rx_offset - 1) {
|
||||||
line_current++;
|
line_current++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// find the next newline
|
||||||
char* newline = strchr(line_current, '\n');
|
char* newline = strchr(line_current, '\n');
|
||||||
if(newline) {
|
if(newline) // newline found
|
||||||
|
{
|
||||||
|
// put a null terminator in place of the newline, to delimit the line string
|
||||||
*newline = '\0';
|
*newline = '\0';
|
||||||
|
|
||||||
|
// attempt to parse the line as a NMEA sentence
|
||||||
gps_uart_parse_nmea(gps_uart, line_current);
|
gps_uart_parse_nmea(gps_uart, line_current);
|
||||||
|
|
||||||
|
// move the cursor to the character after the newline
|
||||||
line_current = newline + 1;
|
line_current = newline + 1;
|
||||||
} else {
|
} else // no more newlines found
|
||||||
if(line_current > (char*)gps_uart->rx_buf) {
|
{
|
||||||
|
if(line_current >
|
||||||
|
(char*)gps_uart->rx_buf) // at least one line was found
|
||||||
|
{
|
||||||
|
// clear parsed lines, and move any leftover bytes to the start of rx_buf
|
||||||
rx_offset = 0;
|
rx_offset = 0;
|
||||||
while(*line_current) {
|
while(
|
||||||
|
*line_current) // stop when the original rx_offset terminator is reached
|
||||||
|
{
|
||||||
gps_uart->rx_buf[rx_offset++] = *(line_current++);
|
gps_uart->rx_buf[rx_offset++] = *(line_current++);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break; // go back to receiving bytes from the serial stream
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -148,6 +176,8 @@ void gps_uart_init_thread(GpsUart* gps_uart) {
|
|||||||
gps_uart->status.time_minutes = 0;
|
gps_uart->status.time_minutes = 0;
|
||||||
gps_uart->status.time_seconds = 0;
|
gps_uart->status.time_seconds = 0;
|
||||||
|
|
||||||
|
gps_uart->rx_stream = furi_stream_buffer_alloc(RX_BUF_SIZE * 5, 1);
|
||||||
|
|
||||||
gps_uart->thread = furi_thread_alloc();
|
gps_uart->thread = furi_thread_alloc();
|
||||||
furi_thread_set_name(gps_uart->thread, "GpsUartWorker");
|
furi_thread_set_name(gps_uart->thread, "GpsUartWorker");
|
||||||
furi_thread_set_stack_size(gps_uart->thread, 1024);
|
furi_thread_set_stack_size(gps_uart->thread, 1024);
|
||||||
@@ -155,6 +185,8 @@ void gps_uart_init_thread(GpsUart* gps_uart) {
|
|||||||
furi_thread_set_callback(gps_uart->thread, gps_uart_worker);
|
furi_thread_set_callback(gps_uart->thread, gps_uart_worker);
|
||||||
|
|
||||||
furi_thread_start(gps_uart->thread);
|
furi_thread_start(gps_uart->thread);
|
||||||
|
|
||||||
|
gps_uart_serial_init(gps_uart);
|
||||||
}
|
}
|
||||||
|
|
||||||
void gps_uart_deinit_thread(GpsUart* gps_uart) {
|
void gps_uart_deinit_thread(GpsUart* gps_uart) {
|
||||||
|
|||||||
46
applications/external/hid_app/hid.c
vendored
@@ -11,8 +11,7 @@ enum HidDebugSubmenuIndex {
|
|||||||
HidSubmenuIndexKeyboard,
|
HidSubmenuIndexKeyboard,
|
||||||
HidSubmenuIndexNumpad,
|
HidSubmenuIndexNumpad,
|
||||||
HidSubmenuIndexMedia,
|
HidSubmenuIndexMedia,
|
||||||
HidSubmenuIndexTikTok,
|
HidSubmenuIndexTikShorts,
|
||||||
HidSubmenuIndexYTShorts,
|
|
||||||
HidSubmenuIndexMouse,
|
HidSubmenuIndexMouse,
|
||||||
HidSubmenuIndexMouseClicker,
|
HidSubmenuIndexMouseClicker,
|
||||||
HidSubmenuIndexMouseJiggler,
|
HidSubmenuIndexMouseJiggler,
|
||||||
@@ -39,12 +38,9 @@ static void hid_submenu_callback(void* context, uint32_t index) {
|
|||||||
} else if(index == HidSubmenuIndexMouse) {
|
} else if(index == HidSubmenuIndexMouse) {
|
||||||
app->view_id = HidViewMouse;
|
app->view_id = HidViewMouse;
|
||||||
view_dispatcher_switch_to_view(app->view_dispatcher, HidViewMouse);
|
view_dispatcher_switch_to_view(app->view_dispatcher, HidViewMouse);
|
||||||
} else if(index == HidSubmenuIndexTikTok) {
|
} else if(index == HidSubmenuIndexTikShorts) {
|
||||||
app->view_id = BtHidViewTikTok;
|
app->view_id = BtHidViewTikShorts;
|
||||||
view_dispatcher_switch_to_view(app->view_dispatcher, BtHidViewTikTok);
|
view_dispatcher_switch_to_view(app->view_dispatcher, BtHidViewTikShorts);
|
||||||
} else if(index == HidSubmenuIndexYTShorts) {
|
|
||||||
app->view_id = BtHidViewYTShorts;
|
|
||||||
view_dispatcher_switch_to_view(app->view_dispatcher, BtHidViewYTShorts);
|
|
||||||
} else if(index == HidSubmenuIndexMouseClicker) {
|
} else if(index == HidSubmenuIndexMouseClicker) {
|
||||||
app->view_id = HidViewMouseClicker;
|
app->view_id = HidViewMouseClicker;
|
||||||
view_dispatcher_switch_to_view(app->view_dispatcher, HidViewMouseClicker);
|
view_dispatcher_switch_to_view(app->view_dispatcher, HidViewMouseClicker);
|
||||||
@@ -73,8 +69,7 @@ static void bt_hid_connection_status_changed_callback(BtStatus status, void* con
|
|||||||
hid_mouse_set_connected_status(hid->hid_mouse, connected);
|
hid_mouse_set_connected_status(hid->hid_mouse, connected);
|
||||||
hid_mouse_clicker_set_connected_status(hid->hid_mouse_clicker, connected);
|
hid_mouse_clicker_set_connected_status(hid->hid_mouse_clicker, connected);
|
||||||
hid_mouse_jiggler_set_connected_status(hid->hid_mouse_jiggler, connected);
|
hid_mouse_jiggler_set_connected_status(hid->hid_mouse_jiggler, connected);
|
||||||
hid_tiktok_set_connected_status(hid->hid_tiktok, connected);
|
hid_tikshorts_set_connected_status(hid->hid_tikshorts, connected);
|
||||||
hid_ytshorts_set_connected_status(hid->hid_ytshorts, connected);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void hid_dialog_callback(DialogExResult result, void* context) {
|
static void hid_dialog_callback(DialogExResult result, void* context) {
|
||||||
@@ -137,14 +132,8 @@ Hid* hid_alloc(HidTransport transport) {
|
|||||||
if(app->transport == HidTransportBle) {
|
if(app->transport == HidTransportBle) {
|
||||||
submenu_add_item(
|
submenu_add_item(
|
||||||
app->device_type_submenu,
|
app->device_type_submenu,
|
||||||
"TikTok Controller",
|
"TikTok / YT Shorts",
|
||||||
HidSubmenuIndexTikTok,
|
HidSubmenuIndexTikShorts,
|
||||||
hid_submenu_callback,
|
|
||||||
app);
|
|
||||||
submenu_add_item(
|
|
||||||
app->device_type_submenu,
|
|
||||||
"YT Shorts Controller",
|
|
||||||
HidSubmenuIndexYTShorts,
|
|
||||||
hid_submenu_callback,
|
hid_submenu_callback,
|
||||||
app);
|
app);
|
||||||
}
|
}
|
||||||
@@ -215,17 +204,11 @@ Hid* hid_app_alloc_view(void* context) {
|
|||||||
view_dispatcher_add_view(
|
view_dispatcher_add_view(
|
||||||
app->view_dispatcher, HidViewMedia, hid_media_get_view(app->hid_media));
|
app->view_dispatcher, HidViewMedia, hid_media_get_view(app->hid_media));
|
||||||
|
|
||||||
// TikTok view
|
// TikTok / YT Shorts view
|
||||||
app->hid_tiktok = hid_tiktok_alloc(app);
|
app->hid_tikshorts = hid_tikshorts_alloc(app);
|
||||||
view_set_previous_callback(hid_tiktok_get_view(app->hid_tiktok), hid_exit_confirm_view);
|
view_set_previous_callback(hid_tikshorts_get_view(app->hid_tikshorts), hid_exit_confirm_view);
|
||||||
view_dispatcher_add_view(
|
view_dispatcher_add_view(
|
||||||
app->view_dispatcher, BtHidViewTikTok, hid_tiktok_get_view(app->hid_tiktok));
|
app->view_dispatcher, BtHidViewTikShorts, hid_tikshorts_get_view(app->hid_tikshorts));
|
||||||
|
|
||||||
// YTShorts view
|
|
||||||
app->hid_ytshorts = hid_ytshorts_alloc(app);
|
|
||||||
view_set_previous_callback(hid_ytshorts_get_view(app->hid_ytshorts), hid_exit_confirm_view);
|
|
||||||
view_dispatcher_add_view(
|
|
||||||
app->view_dispatcher, BtHidViewYTShorts, hid_ytshorts_get_view(app->hid_ytshorts));
|
|
||||||
|
|
||||||
// Mouse view
|
// Mouse view
|
||||||
app->hid_mouse = hid_mouse_alloc(app);
|
app->hid_mouse = hid_mouse_alloc(app);
|
||||||
@@ -241,6 +224,7 @@ Hid* hid_app_alloc_view(void* context) {
|
|||||||
app->view_dispatcher,
|
app->view_dispatcher,
|
||||||
HidViewMouseClicker,
|
HidViewMouseClicker,
|
||||||
hid_mouse_clicker_get_view(app->hid_mouse_clicker));
|
hid_mouse_clicker_get_view(app->hid_mouse_clicker));
|
||||||
|
|
||||||
// Mouse jiggler view
|
// Mouse jiggler view
|
||||||
app->hid_mouse_jiggler = hid_mouse_jiggler_alloc(app);
|
app->hid_mouse_jiggler = hid_mouse_jiggler_alloc(app);
|
||||||
view_set_previous_callback(
|
view_set_previous_callback(
|
||||||
@@ -282,10 +266,8 @@ void hid_free(Hid* app) {
|
|||||||
hid_mouse_clicker_free(app->hid_mouse_clicker);
|
hid_mouse_clicker_free(app->hid_mouse_clicker);
|
||||||
view_dispatcher_remove_view(app->view_dispatcher, HidViewMouseJiggler);
|
view_dispatcher_remove_view(app->view_dispatcher, HidViewMouseJiggler);
|
||||||
hid_mouse_jiggler_free(app->hid_mouse_jiggler);
|
hid_mouse_jiggler_free(app->hid_mouse_jiggler);
|
||||||
view_dispatcher_remove_view(app->view_dispatcher, BtHidViewTikTok);
|
view_dispatcher_remove_view(app->view_dispatcher, BtHidViewTikShorts);
|
||||||
hid_tiktok_free(app->hid_tiktok);
|
hid_tikshorts_free(app->hid_tikshorts);
|
||||||
view_dispatcher_remove_view(app->view_dispatcher, BtHidViewYTShorts);
|
|
||||||
hid_ytshorts_free(app->hid_ytshorts);
|
|
||||||
view_dispatcher_free(app->view_dispatcher);
|
view_dispatcher_free(app->view_dispatcher);
|
||||||
|
|
||||||
// Close records
|
// Close records
|
||||||
|
|||||||
6
applications/external/hid_app/hid.h
vendored
@@ -23,8 +23,7 @@
|
|||||||
#include "views/hid_media.h"
|
#include "views/hid_media.h"
|
||||||
#include "views/hid_mouse.h"
|
#include "views/hid_mouse.h"
|
||||||
#include "views/hid_mouse_jiggler.h"
|
#include "views/hid_mouse_jiggler.h"
|
||||||
#include "views/hid_tiktok.h"
|
#include "views/hid_tikshorts.h"
|
||||||
#include "views/hid_ytshorts.h"
|
|
||||||
#include "views/hid_mouse_clicker.h"
|
#include "views/hid_mouse_clicker.h"
|
||||||
|
|
||||||
#define HID_BT_KEYS_STORAGE_NAME ".bt_hid.keys"
|
#define HID_BT_KEYS_STORAGE_NAME ".bt_hid.keys"
|
||||||
@@ -51,8 +50,7 @@ struct Hid {
|
|||||||
HidMouse* hid_mouse;
|
HidMouse* hid_mouse;
|
||||||
HidMouseClicker* hid_mouse_clicker;
|
HidMouseClicker* hid_mouse_clicker;
|
||||||
HidMouseJiggler* hid_mouse_jiggler;
|
HidMouseJiggler* hid_mouse_jiggler;
|
||||||
HidTikTok* hid_tiktok;
|
HidTikShorts* hid_tikshorts;
|
||||||
HidYTShorts* hid_ytshorts;
|
|
||||||
|
|
||||||
HidTransport transport;
|
HidTransport transport;
|
||||||
uint32_t view_id;
|
uint32_t view_id;
|
||||||
|
|||||||
3
applications/external/hid_app/views.h
vendored
@@ -8,7 +8,6 @@ typedef enum {
|
|||||||
HidViewMouse,
|
HidViewMouse,
|
||||||
HidViewMouseClicker,
|
HidViewMouseClicker,
|
||||||
HidViewMouseJiggler,
|
HidViewMouseJiggler,
|
||||||
BtHidViewTikTok,
|
BtHidViewTikShorts,
|
||||||
BtHidViewYTShorts,
|
|
||||||
HidViewExitConfirm,
|
HidViewExitConfirm,
|
||||||
} HidView;
|
} HidView;
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
#include "hid_ytshorts.h"
|
#include "hid_tikshorts.h"
|
||||||
#include "../hid.h"
|
#include "../hid.h"
|
||||||
#include <gui/elements.h>
|
#include <gui/elements.h>
|
||||||
|
|
||||||
#include "hid_icons.h"
|
#include "hid_icons.h"
|
||||||
|
|
||||||
#define TAG "HidYTShorts"
|
#define TAG "HidTikShorts"
|
||||||
|
|
||||||
struct HidYTShorts {
|
struct HidTikShorts {
|
||||||
View* view;
|
View* view;
|
||||||
Hid* hid;
|
Hid* hid;
|
||||||
};
|
};
|
||||||
@@ -21,11 +21,11 @@ typedef struct {
|
|||||||
bool is_cursor_set;
|
bool is_cursor_set;
|
||||||
bool back_mouse_pressed;
|
bool back_mouse_pressed;
|
||||||
HidTransport transport;
|
HidTransport transport;
|
||||||
} HidYTShortsModel;
|
} HidTikShortsModel;
|
||||||
|
|
||||||
static void hid_ytshorts_draw_callback(Canvas* canvas, void* context) {
|
static void hid_tikshorts_draw_callback(Canvas* canvas, void* context) {
|
||||||
furi_assert(context);
|
furi_assert(context);
|
||||||
HidYTShortsModel* model = context;
|
HidTikShortsModel* model = context;
|
||||||
|
|
||||||
// Header
|
// Header
|
||||||
if(model->transport == HidTransportBle) {
|
if(model->transport == HidTransportBle) {
|
||||||
@@ -37,7 +37,8 @@ static void hid_ytshorts_draw_callback(Canvas* canvas, void* context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
canvas_set_font(canvas, FontPrimary);
|
canvas_set_font(canvas, FontPrimary);
|
||||||
elements_multiline_text_aligned(canvas, 17, 3, AlignLeft, AlignTop, "Shorts");
|
elements_multiline_text_aligned(canvas, 17, 3, AlignLeft, AlignTop, "TikTok /");
|
||||||
|
elements_multiline_text_aligned(canvas, 3, 18, AlignLeft, AlignTop, "YT Shorts");
|
||||||
canvas_set_font(canvas, FontSecondary);
|
canvas_set_font(canvas, FontSecondary);
|
||||||
|
|
||||||
// Keypad circles
|
// Keypad circles
|
||||||
@@ -109,22 +110,21 @@ static void hid_ytshorts_draw_callback(Canvas* canvas, void* context) {
|
|||||||
elements_multiline_text_aligned(canvas, 13, 62, AlignLeft, AlignBottom, "Hold to exit");
|
elements_multiline_text_aligned(canvas, 13, 62, AlignLeft, AlignBottom, "Hold to exit");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void hid_ytshorts_reset_cursor(HidYTShorts* hid_ytshorts) {
|
static void hid_tikshorts_reset_cursor(HidTikShorts* hid_tikshorts) {
|
||||||
// Set cursor to the phone's left up corner
|
// Set cursor to the phone's left up corner
|
||||||
// Delays to guarantee one packet per connection interval
|
// Delays to guarantee one packet per connection interval
|
||||||
for(size_t i = 0; i < 8; i++) {
|
for(size_t i = 0; i < 8; i++) {
|
||||||
hid_hal_mouse_move(hid_ytshorts->hid, -127, -127);
|
hid_hal_mouse_move(hid_tikshorts->hid, -127, -127);
|
||||||
furi_delay_ms(50);
|
furi_delay_ms(50);
|
||||||
}
|
}
|
||||||
// Move cursor from the corner
|
// Move cursor from the corner
|
||||||
hid_hal_mouse_move(hid_ytshorts->hid, 40, 120);
|
hid_hal_mouse_move(hid_tikshorts->hid, 20, 120);
|
||||||
hid_hal_mouse_move(hid_ytshorts->hid, 0, 120);
|
|
||||||
furi_delay_ms(50);
|
furi_delay_ms(50);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void hid_ytshorts_process_press(
|
static void hid_tikshorts_process_press(
|
||||||
HidYTShorts* hid_ytshorts,
|
HidTikShorts* hid_tikshorts,
|
||||||
HidYTShortsModel* model,
|
HidTikShortsModel* model,
|
||||||
InputEvent* event) {
|
InputEvent* event) {
|
||||||
if(event->key == InputKeyUp) {
|
if(event->key == InputKeyUp) {
|
||||||
model->up_pressed = true;
|
model->up_pressed = true;
|
||||||
@@ -132,10 +132,10 @@ static void hid_ytshorts_process_press(
|
|||||||
model->down_pressed = true;
|
model->down_pressed = true;
|
||||||
} else if(event->key == InputKeyLeft) {
|
} else if(event->key == InputKeyLeft) {
|
||||||
model->left_pressed = true;
|
model->left_pressed = true;
|
||||||
hid_hal_consumer_key_press(hid_ytshorts->hid, HID_CONSUMER_VOLUME_DECREMENT);
|
hid_hal_consumer_key_press(hid_tikshorts->hid, HID_CONSUMER_VOLUME_DECREMENT);
|
||||||
} else if(event->key == InputKeyRight) {
|
} else if(event->key == InputKeyRight) {
|
||||||
model->right_pressed = true;
|
model->right_pressed = true;
|
||||||
hid_hal_consumer_key_press(hid_ytshorts->hid, HID_CONSUMER_VOLUME_INCREMENT);
|
hid_hal_consumer_key_press(hid_tikshorts->hid, HID_CONSUMER_VOLUME_INCREMENT);
|
||||||
} else if(event->key == InputKeyOk) {
|
} else if(event->key == InputKeyOk) {
|
||||||
model->ok_pressed = true;
|
model->ok_pressed = true;
|
||||||
} else if(event->key == InputKeyBack) {
|
} else if(event->key == InputKeyBack) {
|
||||||
@@ -143,9 +143,9 @@ static void hid_ytshorts_process_press(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void hid_ytshorts_process_release(
|
static void hid_tikshorts_process_release(
|
||||||
HidYTShorts* hid_ytshorts,
|
HidTikShorts* hid_tikshorts,
|
||||||
HidYTShortsModel* model,
|
HidTikShortsModel* model,
|
||||||
InputEvent* event) {
|
InputEvent* event) {
|
||||||
if(event->key == InputKeyUp) {
|
if(event->key == InputKeyUp) {
|
||||||
model->up_pressed = false;
|
model->up_pressed = false;
|
||||||
@@ -153,10 +153,10 @@ static void hid_ytshorts_process_release(
|
|||||||
model->down_pressed = false;
|
model->down_pressed = false;
|
||||||
} else if(event->key == InputKeyLeft) {
|
} else if(event->key == InputKeyLeft) {
|
||||||
model->left_pressed = false;
|
model->left_pressed = false;
|
||||||
hid_hal_consumer_key_release(hid_ytshorts->hid, HID_CONSUMER_VOLUME_DECREMENT);
|
hid_hal_consumer_key_release(hid_tikshorts->hid, HID_CONSUMER_VOLUME_DECREMENT);
|
||||||
} else if(event->key == InputKeyRight) {
|
} else if(event->key == InputKeyRight) {
|
||||||
model->right_pressed = false;
|
model->right_pressed = false;
|
||||||
hid_hal_consumer_key_release(hid_ytshorts->hid, HID_CONSUMER_VOLUME_INCREMENT);
|
hid_hal_consumer_key_release(hid_tikshorts->hid, HID_CONSUMER_VOLUME_INCREMENT);
|
||||||
} else if(event->key == InputKeyOk) {
|
} else if(event->key == InputKeyOk) {
|
||||||
model->ok_pressed = false;
|
model->ok_pressed = false;
|
||||||
} else if(event->key == InputKeyBack) {
|
} else if(event->key == InputKeyBack) {
|
||||||
@@ -164,62 +164,61 @@ static void hid_ytshorts_process_release(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool hid_ytshorts_input_callback(InputEvent* event, void* context) {
|
static bool hid_tikshorts_input_callback(InputEvent* event, void* context) {
|
||||||
furi_assert(context);
|
furi_assert(context);
|
||||||
HidYTShorts* hid_ytshorts = context;
|
HidTikShorts* hid_tikshorts = context;
|
||||||
bool consumed = false;
|
bool consumed = false;
|
||||||
|
|
||||||
with_view_model(
|
with_view_model(
|
||||||
hid_ytshorts->view,
|
hid_tikshorts->view,
|
||||||
HidYTShortsModel * model,
|
HidTikShortsModel * model,
|
||||||
{
|
{
|
||||||
if(event->type == InputTypePress) {
|
if(event->type == InputTypePress) {
|
||||||
hid_ytshorts_process_press(hid_ytshorts, model, event);
|
hid_tikshorts_process_press(hid_tikshorts, model, event);
|
||||||
if(model->connected && !model->is_cursor_set) {
|
if(model->connected && !model->is_cursor_set) {
|
||||||
hid_ytshorts_reset_cursor(hid_ytshorts);
|
hid_tikshorts_reset_cursor(hid_tikshorts);
|
||||||
model->is_cursor_set = true;
|
model->is_cursor_set = true;
|
||||||
}
|
}
|
||||||
consumed = true;
|
consumed = true;
|
||||||
} else if(event->type == InputTypeRelease) {
|
} else if(event->type == InputTypeRelease) {
|
||||||
hid_ytshorts_process_release(hid_ytshorts, model, event);
|
hid_tikshorts_process_release(hid_tikshorts, model, event);
|
||||||
consumed = true;
|
consumed = true;
|
||||||
} else if(event->type == InputTypeShort) {
|
} else if(event->type == InputTypeShort) {
|
||||||
if(event->key == InputKeyOk) {
|
if(event->key == InputKeyOk) {
|
||||||
hid_hal_mouse_press(hid_ytshorts->hid, HID_MOUSE_BTN_LEFT);
|
hid_hal_mouse_press(hid_tikshorts->hid, HID_MOUSE_BTN_LEFT);
|
||||||
furi_delay_ms(50);
|
furi_delay_ms(25);
|
||||||
hid_hal_mouse_release(hid_ytshorts->hid, HID_MOUSE_BTN_LEFT);
|
hid_hal_mouse_release(hid_tikshorts->hid, HID_MOUSE_BTN_LEFT);
|
||||||
furi_delay_ms(50);
|
furi_delay_ms(100);
|
||||||
hid_hal_mouse_press(hid_ytshorts->hid, HID_MOUSE_BTN_LEFT);
|
hid_hal_mouse_press(hid_tikshorts->hid, HID_MOUSE_BTN_LEFT);
|
||||||
furi_delay_ms(50);
|
furi_delay_ms(25);
|
||||||
hid_hal_mouse_release(hid_ytshorts->hid, HID_MOUSE_BTN_LEFT);
|
hid_hal_mouse_release(hid_tikshorts->hid, HID_MOUSE_BTN_LEFT);
|
||||||
consumed = true;
|
consumed = true;
|
||||||
} else if(event->key == InputKeyDown) {
|
} else if(event->key == InputKeyDown) {
|
||||||
// Swipe to new video
|
// Swipe to next video
|
||||||
hid_hal_mouse_scroll(hid_ytshorts->hid, 6);
|
hid_hal_mouse_scroll(hid_tikshorts->hid, 6);
|
||||||
hid_hal_mouse_scroll(hid_ytshorts->hid, 8);
|
hid_hal_mouse_scroll(hid_tikshorts->hid, 8);
|
||||||
hid_hal_mouse_scroll(hid_ytshorts->hid, 10);
|
hid_hal_mouse_scroll(hid_tikshorts->hid, 10);
|
||||||
hid_hal_mouse_scroll(hid_ytshorts->hid, 8);
|
hid_hal_mouse_scroll(hid_tikshorts->hid, 8);
|
||||||
hid_hal_mouse_scroll(hid_ytshorts->hid, 6);
|
hid_hal_mouse_scroll(hid_tikshorts->hid, 6);
|
||||||
consumed = true;
|
consumed = true;
|
||||||
} else if(event->key == InputKeyUp) {
|
} else if(event->key == InputKeyUp) {
|
||||||
// Swipe to previous video
|
// Swipe to previous video
|
||||||
hid_hal_mouse_scroll(hid_ytshorts->hid, -6);
|
hid_hal_mouse_scroll(hid_tikshorts->hid, -6);
|
||||||
hid_hal_mouse_scroll(hid_ytshorts->hid, -8);
|
hid_hal_mouse_scroll(hid_tikshorts->hid, -8);
|
||||||
hid_hal_mouse_scroll(hid_ytshorts->hid, -10);
|
hid_hal_mouse_scroll(hid_tikshorts->hid, -10);
|
||||||
hid_hal_mouse_scroll(hid_ytshorts->hid, -8);
|
hid_hal_mouse_scroll(hid_tikshorts->hid, -8);
|
||||||
hid_hal_mouse_scroll(hid_ytshorts->hid, -6);
|
hid_hal_mouse_scroll(hid_tikshorts->hid, -6);
|
||||||
consumed = true;
|
consumed = true;
|
||||||
} else if(event->key == InputKeyBack) {
|
} else if(event->key == InputKeyBack) {
|
||||||
// Pause
|
// Pause
|
||||||
hid_hal_mouse_press(hid_ytshorts->hid, HID_MOUSE_BTN_LEFT);
|
hid_hal_mouse_press(hid_tikshorts->hid, HID_MOUSE_BTN_LEFT);
|
||||||
furi_delay_ms(50);
|
|
||||||
hid_hal_mouse_release(hid_ytshorts->hid, HID_MOUSE_BTN_LEFT);
|
|
||||||
furi_delay_ms(50);
|
furi_delay_ms(50);
|
||||||
|
hid_hal_mouse_release(hid_tikshorts->hid, HID_MOUSE_BTN_LEFT);
|
||||||
consumed = true;
|
consumed = true;
|
||||||
}
|
}
|
||||||
} else if(event->type == InputTypeLong) {
|
} else if(event->type == InputTypeLong) {
|
||||||
if(event->key == InputKeyBack) {
|
if(event->key == InputKeyBack) {
|
||||||
hid_hal_consumer_key_release_all(hid_ytshorts->hid);
|
hid_hal_consumer_key_release_all(hid_tikshorts->hid);
|
||||||
model->is_cursor_set = false;
|
model->is_cursor_set = false;
|
||||||
consumed = false;
|
consumed = false;
|
||||||
}
|
}
|
||||||
@@ -230,40 +229,40 @@ static bool hid_ytshorts_input_callback(InputEvent* event, void* context) {
|
|||||||
return consumed;
|
return consumed;
|
||||||
}
|
}
|
||||||
|
|
||||||
HidYTShorts* hid_ytshorts_alloc(Hid* bt_hid) {
|
HidTikShorts* hid_tikshorts_alloc(Hid* bt_hid) {
|
||||||
HidYTShorts* hid_ytshorts = malloc(sizeof(HidYTShorts));
|
HidTikShorts* hid_tikshorts = malloc(sizeof(HidTikShorts));
|
||||||
hid_ytshorts->hid = bt_hid;
|
hid_tikshorts->hid = bt_hid;
|
||||||
hid_ytshorts->view = view_alloc();
|
hid_tikshorts->view = view_alloc();
|
||||||
view_set_context(hid_ytshorts->view, hid_ytshorts);
|
view_set_context(hid_tikshorts->view, hid_tikshorts);
|
||||||
view_allocate_model(hid_ytshorts->view, ViewModelTypeLocking, sizeof(HidYTShortsModel));
|
view_allocate_model(hid_tikshorts->view, ViewModelTypeLocking, sizeof(HidTikShortsModel));
|
||||||
view_set_draw_callback(hid_ytshorts->view, hid_ytshorts_draw_callback);
|
view_set_draw_callback(hid_tikshorts->view, hid_tikshorts_draw_callback);
|
||||||
view_set_input_callback(hid_ytshorts->view, hid_ytshorts_input_callback);
|
view_set_input_callback(hid_tikshorts->view, hid_tikshorts_input_callback);
|
||||||
|
|
||||||
with_view_model(
|
with_view_model(
|
||||||
hid_ytshorts->view,
|
hid_tikshorts->view,
|
||||||
HidYTShortsModel * model,
|
HidTikShortsModel * model,
|
||||||
{ model->transport = bt_hid->transport; },
|
{ model->transport = bt_hid->transport; },
|
||||||
true);
|
true);
|
||||||
|
|
||||||
return hid_ytshorts;
|
return hid_tikshorts;
|
||||||
}
|
}
|
||||||
|
|
||||||
void hid_ytshorts_free(HidYTShorts* hid_ytshorts) {
|
void hid_tikshorts_free(HidTikShorts* hid_tikshorts) {
|
||||||
furi_assert(hid_ytshorts);
|
furi_assert(hid_tikshorts);
|
||||||
view_free(hid_ytshorts->view);
|
view_free(hid_tikshorts->view);
|
||||||
free(hid_ytshorts);
|
free(hid_tikshorts);
|
||||||
}
|
}
|
||||||
|
|
||||||
View* hid_ytshorts_get_view(HidYTShorts* hid_ytshorts) {
|
View* hid_tikshorts_get_view(HidTikShorts* hid_tikshorts) {
|
||||||
furi_assert(hid_ytshorts);
|
furi_assert(hid_tikshorts);
|
||||||
return hid_ytshorts->view;
|
return hid_tikshorts->view;
|
||||||
}
|
}
|
||||||
|
|
||||||
void hid_ytshorts_set_connected_status(HidYTShorts* hid_ytshorts, bool connected) {
|
void hid_tikshorts_set_connected_status(HidTikShorts* hid_tikshorts, bool connected) {
|
||||||
furi_assert(hid_ytshorts);
|
furi_assert(hid_tikshorts);
|
||||||
with_view_model(
|
with_view_model(
|
||||||
hid_ytshorts->view,
|
hid_tikshorts->view,
|
||||||
HidYTShortsModel * model,
|
HidTikShortsModel * model,
|
||||||
{
|
{
|
||||||
model->connected = connected;
|
model->connected = connected;
|
||||||
model->is_cursor_set = false;
|
model->is_cursor_set = false;
|
||||||
14
applications/external/hid_app/views/hid_tikshorts.h
vendored
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <gui/view.h>
|
||||||
|
|
||||||
|
typedef struct Hid Hid;
|
||||||
|
typedef struct HidTikShorts HidTikShorts;
|
||||||
|
|
||||||
|
HidTikShorts* hid_tikshorts_alloc(Hid* bt_hid);
|
||||||
|
|
||||||
|
void hid_tikshorts_free(HidTikShorts* hid_tikshorts);
|
||||||
|
|
||||||
|
View* hid_tikshorts_get_view(HidTikShorts* hid_tikshorts);
|
||||||
|
|
||||||
|
void hid_tikshorts_set_connected_status(HidTikShorts* hid_tikshorts, bool connected);
|
||||||
256
applications/external/hid_app/views/hid_tiktok.c
vendored
@@ -1,256 +0,0 @@
|
|||||||
#include "hid_tiktok.h"
|
|
||||||
#include "../hid.h"
|
|
||||||
#include <gui/elements.h>
|
|
||||||
|
|
||||||
#include "hid_icons.h"
|
|
||||||
|
|
||||||
#define TAG "HidTikTok"
|
|
||||||
|
|
||||||
struct HidTikTok {
|
|
||||||
View* view;
|
|
||||||
Hid* hid;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
bool left_pressed;
|
|
||||||
bool up_pressed;
|
|
||||||
bool right_pressed;
|
|
||||||
bool down_pressed;
|
|
||||||
bool ok_pressed;
|
|
||||||
bool connected;
|
|
||||||
bool is_cursor_set;
|
|
||||||
bool back_mouse_pressed;
|
|
||||||
HidTransport transport;
|
|
||||||
} HidTikTokModel;
|
|
||||||
|
|
||||||
static void hid_tiktok_draw_callback(Canvas* canvas, void* context) {
|
|
||||||
furi_assert(context);
|
|
||||||
HidTikTokModel* model = context;
|
|
||||||
|
|
||||||
// Header
|
|
||||||
if(model->transport == HidTransportBle) {
|
|
||||||
if(model->connected) {
|
|
||||||
canvas_draw_icon(canvas, 0, 0, &I_Ble_connected_15x15);
|
|
||||||
} else {
|
|
||||||
canvas_draw_icon(canvas, 0, 0, &I_Ble_disconnected_15x15);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
canvas_set_font(canvas, FontPrimary);
|
|
||||||
elements_multiline_text_aligned(canvas, 17, 3, AlignLeft, AlignTop, "TikTok");
|
|
||||||
canvas_set_font(canvas, FontSecondary);
|
|
||||||
|
|
||||||
// Keypad circles
|
|
||||||
canvas_draw_icon(canvas, 58, 3, &I_OutCircles);
|
|
||||||
|
|
||||||
// Pause
|
|
||||||
if(model->back_mouse_pressed) {
|
|
||||||
canvas_set_bitmap_mode(canvas, 1);
|
|
||||||
canvas_draw_icon(canvas, 107, 33, &I_Pressed_Button_19x19);
|
|
||||||
canvas_set_bitmap_mode(canvas, 0);
|
|
||||||
canvas_set_color(canvas, ColorWhite);
|
|
||||||
}
|
|
||||||
canvas_draw_icon(canvas, 113, 37, &I_Pause_icon_9x9);
|
|
||||||
canvas_set_color(canvas, ColorBlack);
|
|
||||||
|
|
||||||
// Up
|
|
||||||
if(model->up_pressed) {
|
|
||||||
canvas_set_bitmap_mode(canvas, 1);
|
|
||||||
canvas_draw_icon(canvas, 68, 6, &I_S_UP);
|
|
||||||
canvas_set_bitmap_mode(canvas, 0);
|
|
||||||
canvas_set_color(canvas, ColorWhite);
|
|
||||||
}
|
|
||||||
canvas_draw_icon(canvas, 80, 8, &I_Arr_up_7x9);
|
|
||||||
canvas_set_color(canvas, ColorBlack);
|
|
||||||
|
|
||||||
// Down
|
|
||||||
if(model->down_pressed) {
|
|
||||||
canvas_set_bitmap_mode(canvas, 1);
|
|
||||||
canvas_draw_icon(canvas, 68, 36, &I_S_DOWN);
|
|
||||||
canvas_set_bitmap_mode(canvas, 0);
|
|
||||||
canvas_set_color(canvas, ColorWhite);
|
|
||||||
}
|
|
||||||
canvas_draw_icon(canvas, 80, 40, &I_Arr_dwn_7x9);
|
|
||||||
canvas_set_color(canvas, ColorBlack);
|
|
||||||
|
|
||||||
// Left
|
|
||||||
if(model->left_pressed) {
|
|
||||||
canvas_set_bitmap_mode(canvas, 1);
|
|
||||||
canvas_draw_icon(canvas, 61, 13, &I_S_LEFT);
|
|
||||||
canvas_set_bitmap_mode(canvas, 0);
|
|
||||||
canvas_set_color(canvas, ColorWhite);
|
|
||||||
}
|
|
||||||
canvas_draw_icon(canvas, 64, 25, &I_Voldwn_6x6);
|
|
||||||
canvas_set_color(canvas, ColorBlack);
|
|
||||||
|
|
||||||
// Right
|
|
||||||
if(model->right_pressed) {
|
|
||||||
canvas_set_bitmap_mode(canvas, 1);
|
|
||||||
canvas_draw_icon(canvas, 91, 13, &I_S_RIGHT);
|
|
||||||
canvas_set_bitmap_mode(canvas, 0);
|
|
||||||
canvas_set_color(canvas, ColorWhite);
|
|
||||||
}
|
|
||||||
canvas_draw_icon(canvas, 95, 25, &I_Volup_8x6);
|
|
||||||
canvas_set_color(canvas, ColorBlack);
|
|
||||||
|
|
||||||
// Ok
|
|
||||||
if(model->ok_pressed) {
|
|
||||||
canvas_set_bitmap_mode(canvas, 1);
|
|
||||||
canvas_draw_icon(canvas, 74, 19, &I_Pressed_Button_19x19);
|
|
||||||
canvas_set_bitmap_mode(canvas, 0);
|
|
||||||
canvas_set_color(canvas, ColorWhite);
|
|
||||||
}
|
|
||||||
canvas_draw_icon(canvas, 78, 25, &I_Like_def_11x9);
|
|
||||||
canvas_set_color(canvas, ColorBlack);
|
|
||||||
|
|
||||||
// Exit
|
|
||||||
canvas_draw_icon(canvas, 0, 54, &I_Pin_back_arrow_10x8);
|
|
||||||
canvas_set_font(canvas, FontSecondary);
|
|
||||||
elements_multiline_text_aligned(canvas, 13, 62, AlignLeft, AlignBottom, "Hold to exit");
|
|
||||||
}
|
|
||||||
|
|
||||||
static void hid_tiktok_reset_cursor(HidTikTok* hid_tiktok) {
|
|
||||||
// Set cursor to the phone's left up corner
|
|
||||||
// Delays to guarantee one packet per connection interval
|
|
||||||
for(size_t i = 0; i < 8; i++) {
|
|
||||||
hid_hal_mouse_move(hid_tiktok->hid, -127, -127);
|
|
||||||
furi_delay_ms(50);
|
|
||||||
}
|
|
||||||
// Move cursor from the corner
|
|
||||||
hid_hal_mouse_move(hid_tiktok->hid, 40, 120);
|
|
||||||
hid_hal_mouse_move(hid_tiktok->hid, 0, 120);
|
|
||||||
furi_delay_ms(50);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
hid_tiktok_process_press(HidTikTok* hid_tiktok, HidTikTokModel* model, InputEvent* event) {
|
|
||||||
if(event->key == InputKeyUp) {
|
|
||||||
model->up_pressed = true;
|
|
||||||
} else if(event->key == InputKeyDown) {
|
|
||||||
model->down_pressed = true;
|
|
||||||
} else if(event->key == InputKeyLeft) {
|
|
||||||
model->left_pressed = true;
|
|
||||||
hid_hal_consumer_key_press(hid_tiktok->hid, HID_CONSUMER_VOLUME_DECREMENT);
|
|
||||||
} else if(event->key == InputKeyRight) {
|
|
||||||
model->right_pressed = true;
|
|
||||||
hid_hal_consumer_key_press(hid_tiktok->hid, HID_CONSUMER_VOLUME_INCREMENT);
|
|
||||||
} else if(event->key == InputKeyOk) {
|
|
||||||
model->ok_pressed = true;
|
|
||||||
} else if(event->key == InputKeyBack) {
|
|
||||||
model->back_mouse_pressed = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
hid_tiktok_process_release(HidTikTok* hid_tiktok, HidTikTokModel* model, InputEvent* event) {
|
|
||||||
if(event->key == InputKeyUp) {
|
|
||||||
model->up_pressed = false;
|
|
||||||
} else if(event->key == InputKeyDown) {
|
|
||||||
model->down_pressed = false;
|
|
||||||
} else if(event->key == InputKeyLeft) {
|
|
||||||
model->left_pressed = false;
|
|
||||||
hid_hal_consumer_key_release(hid_tiktok->hid, HID_CONSUMER_VOLUME_DECREMENT);
|
|
||||||
} else if(event->key == InputKeyRight) {
|
|
||||||
model->right_pressed = false;
|
|
||||||
hid_hal_consumer_key_release(hid_tiktok->hid, HID_CONSUMER_VOLUME_INCREMENT);
|
|
||||||
} else if(event->key == InputKeyOk) {
|
|
||||||
model->ok_pressed = false;
|
|
||||||
} else if(event->key == InputKeyBack) {
|
|
||||||
model->back_mouse_pressed = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool hid_tiktok_input_callback(InputEvent* event, void* context) {
|
|
||||||
furi_assert(context);
|
|
||||||
HidTikTok* hid_tiktok = context;
|
|
||||||
bool consumed = false;
|
|
||||||
|
|
||||||
with_view_model(
|
|
||||||
hid_tiktok->view,
|
|
||||||
HidTikTokModel * model,
|
|
||||||
{
|
|
||||||
if(event->type == InputTypePress) {
|
|
||||||
hid_tiktok_process_press(hid_tiktok, model, event);
|
|
||||||
if(model->connected && !model->is_cursor_set) {
|
|
||||||
hid_tiktok_reset_cursor(hid_tiktok);
|
|
||||||
model->is_cursor_set = true;
|
|
||||||
}
|
|
||||||
consumed = true;
|
|
||||||
} else if(event->type == InputTypeRelease) {
|
|
||||||
hid_tiktok_process_release(hid_tiktok, model, event);
|
|
||||||
consumed = true;
|
|
||||||
} else if(event->type == InputTypeShort) {
|
|
||||||
if(event->key == InputKeyOk) {
|
|
||||||
hid_hal_mouse_press(hid_tiktok->hid, HID_MOUSE_BTN_LEFT);
|
|
||||||
furi_delay_ms(25);
|
|
||||||
hid_hal_mouse_release(hid_tiktok->hid, HID_MOUSE_BTN_LEFT);
|
|
||||||
furi_delay_ms(100);
|
|
||||||
hid_hal_mouse_press(hid_tiktok->hid, HID_MOUSE_BTN_LEFT);
|
|
||||||
furi_delay_ms(25);
|
|
||||||
hid_hal_mouse_release(hid_tiktok->hid, HID_MOUSE_BTN_LEFT);
|
|
||||||
consumed = true;
|
|
||||||
} else if(event->key == InputKeyDown) {
|
|
||||||
// Swipe to previous video
|
|
||||||
hid_hal_mouse_scroll(hid_tiktok->hid, 19);
|
|
||||||
consumed = true;
|
|
||||||
} else if(event->key == InputKeyUp) {
|
|
||||||
// Swipe to new video
|
|
||||||
hid_hal_mouse_scroll(hid_tiktok->hid, -19);
|
|
||||||
consumed = true;
|
|
||||||
} else if(event->key == InputKeyBack) {
|
|
||||||
// Pause
|
|
||||||
hid_hal_mouse_press(hid_tiktok->hid, HID_MOUSE_BTN_LEFT);
|
|
||||||
furi_delay_ms(50);
|
|
||||||
hid_hal_mouse_release(hid_tiktok->hid, HID_MOUSE_BTN_LEFT);
|
|
||||||
consumed = true;
|
|
||||||
}
|
|
||||||
} else if(event->type == InputTypeLong) {
|
|
||||||
if(event->key == InputKeyBack) {
|
|
||||||
hid_hal_consumer_key_release_all(hid_tiktok->hid);
|
|
||||||
model->is_cursor_set = false;
|
|
||||||
consumed = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
true);
|
|
||||||
|
|
||||||
return consumed;
|
|
||||||
}
|
|
||||||
|
|
||||||
HidTikTok* hid_tiktok_alloc(Hid* bt_hid) {
|
|
||||||
HidTikTok* hid_tiktok = malloc(sizeof(HidTikTok));
|
|
||||||
hid_tiktok->hid = bt_hid;
|
|
||||||
hid_tiktok->view = view_alloc();
|
|
||||||
view_set_context(hid_tiktok->view, hid_tiktok);
|
|
||||||
view_allocate_model(hid_tiktok->view, ViewModelTypeLocking, sizeof(HidTikTokModel));
|
|
||||||
view_set_draw_callback(hid_tiktok->view, hid_tiktok_draw_callback);
|
|
||||||
view_set_input_callback(hid_tiktok->view, hid_tiktok_input_callback);
|
|
||||||
|
|
||||||
with_view_model(
|
|
||||||
hid_tiktok->view, HidTikTokModel * model, { model->transport = bt_hid->transport; }, true);
|
|
||||||
|
|
||||||
return hid_tiktok;
|
|
||||||
}
|
|
||||||
|
|
||||||
void hid_tiktok_free(HidTikTok* hid_tiktok) {
|
|
||||||
furi_assert(hid_tiktok);
|
|
||||||
view_free(hid_tiktok->view);
|
|
||||||
free(hid_tiktok);
|
|
||||||
}
|
|
||||||
|
|
||||||
View* hid_tiktok_get_view(HidTikTok* hid_tiktok) {
|
|
||||||
furi_assert(hid_tiktok);
|
|
||||||
return hid_tiktok->view;
|
|
||||||
}
|
|
||||||
|
|
||||||
void hid_tiktok_set_connected_status(HidTikTok* hid_tiktok, bool connected) {
|
|
||||||
furi_assert(hid_tiktok);
|
|
||||||
with_view_model(
|
|
||||||
hid_tiktok->view,
|
|
||||||
HidTikTokModel * model,
|
|
||||||
{
|
|
||||||
model->connected = connected;
|
|
||||||
model->is_cursor_set = false;
|
|
||||||
},
|
|
||||||
true);
|
|
||||||
}
|
|
||||||
14
applications/external/hid_app/views/hid_tiktok.h
vendored
@@ -1,14 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <gui/view.h>
|
|
||||||
|
|
||||||
typedef struct Hid Hid;
|
|
||||||
typedef struct HidTikTok HidTikTok;
|
|
||||||
|
|
||||||
HidTikTok* hid_tiktok_alloc(Hid* bt_hid);
|
|
||||||
|
|
||||||
void hid_tiktok_free(HidTikTok* hid_tiktok);
|
|
||||||
|
|
||||||
View* hid_tiktok_get_view(HidTikTok* hid_tiktok);
|
|
||||||
|
|
||||||
void hid_tiktok_set_connected_status(HidTikTok* hid_tiktok, bool connected);
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <gui/view.h>
|
|
||||||
|
|
||||||
typedef struct Hid Hid;
|
|
||||||
typedef struct HidYTShorts HidYTShorts;
|
|
||||||
|
|
||||||
HidYTShorts* hid_ytshorts_alloc(Hid* bt_hid);
|
|
||||||
|
|
||||||
void hid_ytshorts_free(HidYTShorts* hid_ytshorts);
|
|
||||||
|
|
||||||
View* hid_ytshorts_get_view(HidYTShorts* hid_ytshorts);
|
|
||||||
|
|
||||||
void hid_ytshorts_set_connected_status(HidYTShorts* hid_ytshorts, bool connected);
|
|
||||||
@@ -10,7 +10,7 @@ App(
|
|||||||
],
|
],
|
||||||
stack_size=1 * 1024,
|
stack_size=1 * 1024,
|
||||||
fap_icon="mfkey.png",
|
fap_icon="mfkey.png",
|
||||||
fap_category="Tools",
|
fap_category="NFC",
|
||||||
fap_author="noproto",
|
fap_author="noproto",
|
||||||
fap_icon_assets="images",
|
fap_icon_assets="images",
|
||||||
fap_weburl="https://github.com/noproto/FlipperMfkey",
|
fap_weburl="https://github.com/noproto/FlipperMfkey",
|
||||||
|
|||||||
674
applications/external/mifare_nested/LICENSE.md
vendored
Normal file
@@ -0,0 +1,674 @@
|
|||||||
|
GNU GENERAL PUBLIC LICENSE
|
||||||
|
Version 3, 29 June 2007
|
||||||
|
|
||||||
|
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
Preamble
|
||||||
|
|
||||||
|
The GNU General Public License is a free, copyleft license for
|
||||||
|
software and other kinds of works.
|
||||||
|
|
||||||
|
The licenses for most software and other practical works are designed
|
||||||
|
to take away your freedom to share and change the works. By contrast,
|
||||||
|
the GNU General Public License is intended to guarantee your freedom to
|
||||||
|
share and change all versions of a program--to make sure it remains free
|
||||||
|
software for all its users. We, the Free Software Foundation, use the
|
||||||
|
GNU General Public License for most of our software; it applies also to
|
||||||
|
any other work released this way by its authors. You can apply it to
|
||||||
|
your programs, too.
|
||||||
|
|
||||||
|
When we speak of free software, we are referring to freedom, not
|
||||||
|
price. Our General Public Licenses are designed to make sure that you
|
||||||
|
have the freedom to distribute copies of free software (and charge for
|
||||||
|
them if you wish), that you receive source code or can get it if you
|
||||||
|
want it, that you can change the software or use pieces of it in new
|
||||||
|
free programs, and that you know you can do these things.
|
||||||
|
|
||||||
|
To protect your rights, we need to prevent others from denying you
|
||||||
|
these rights or asking you to surrender the rights. Therefore, you have
|
||||||
|
certain responsibilities if you distribute copies of the software, or if
|
||||||
|
you modify it: responsibilities to respect the freedom of others.
|
||||||
|
|
||||||
|
For example, if you distribute copies of such a program, whether
|
||||||
|
gratis or for a fee, you must pass on to the recipients the same
|
||||||
|
freedoms that you received. You must make sure that they, too, receive
|
||||||
|
or can get the source code. And you must show them these terms so they
|
||||||
|
know their rights.
|
||||||
|
|
||||||
|
Developers that use the GNU GPL protect your rights with two steps:
|
||||||
|
(1) assert copyright on the software, and (2) offer you this License
|
||||||
|
giving you legal permission to copy, distribute and/or modify it.
|
||||||
|
|
||||||
|
For the developers' and authors' protection, the GPL clearly explains
|
||||||
|
that there is no warranty for this free software. For both users' and
|
||||||
|
authors' sake, the GPL requires that modified versions be marked as
|
||||||
|
changed, so that their problems will not be attributed erroneously to
|
||||||
|
authors of previous versions.
|
||||||
|
|
||||||
|
Some devices are designed to deny users access to install or run
|
||||||
|
modified versions of the software inside them, although the manufacturer
|
||||||
|
can do so. This is fundamentally incompatible with the aim of
|
||||||
|
protecting users' freedom to change the software. The systematic
|
||||||
|
pattern of such abuse occurs in the area of products for individuals to
|
||||||
|
use, which is precisely where it is most unacceptable. Therefore, we
|
||||||
|
have designed this version of the GPL to prohibit the practice for those
|
||||||
|
products. If such problems arise substantially in other domains, we
|
||||||
|
stand ready to extend this provision to those domains in future versions
|
||||||
|
of the GPL, as needed to protect the freedom of users.
|
||||||
|
|
||||||
|
Finally, every program is threatened constantly by software patents.
|
||||||
|
States should not allow patents to restrict development and use of
|
||||||
|
software on general-purpose computers, but in those that do, we wish to
|
||||||
|
avoid the special danger that patents applied to a free program could
|
||||||
|
make it effectively proprietary. To prevent this, the GPL assures that
|
||||||
|
patents cannot be used to render the program non-free.
|
||||||
|
|
||||||
|
The precise terms and conditions for copying, distribution and
|
||||||
|
modification follow.
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
0. Definitions.
|
||||||
|
|
||||||
|
"This License" refers to version 3 of the GNU General Public License.
|
||||||
|
|
||||||
|
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||||
|
works, such as semiconductor masks.
|
||||||
|
|
||||||
|
"The Program" refers to any copyrightable work licensed under this
|
||||||
|
License. Each licensee is addressed as "you". "Licensees" and
|
||||||
|
"recipients" may be individuals or organizations.
|
||||||
|
|
||||||
|
To "modify" a work means to copy from or adapt all or part of the work
|
||||||
|
in a fashion requiring copyright permission, other than the making of an
|
||||||
|
exact copy. The resulting work is called a "modified version" of the
|
||||||
|
earlier work or a work "based on" the earlier work.
|
||||||
|
|
||||||
|
A "covered work" means either the unmodified Program or a work based
|
||||||
|
on the Program.
|
||||||
|
|
||||||
|
To "propagate" a work means to do anything with it that, without
|
||||||
|
permission, would make you directly or secondarily liable for
|
||||||
|
infringement under applicable copyright law, except executing it on a
|
||||||
|
computer or modifying a private copy. Propagation includes copying,
|
||||||
|
distribution (with or without modification), making available to the
|
||||||
|
public, and in some countries other activities as well.
|
||||||
|
|
||||||
|
To "convey" a work means any kind of propagation that enables other
|
||||||
|
parties to make or receive copies. Mere interaction with a user through
|
||||||
|
a computer network, with no transfer of a copy, is not conveying.
|
||||||
|
|
||||||
|
An interactive user interface displays "Appropriate Legal Notices"
|
||||||
|
to the extent that it includes a convenient and prominently visible
|
||||||
|
feature that (1) displays an appropriate copyright notice, and (2)
|
||||||
|
tells the user that there is no warranty for the work (except to the
|
||||||
|
extent that warranties are provided), that licensees may convey the
|
||||||
|
work under this License, and how to view a copy of this License. If
|
||||||
|
the interface presents a list of user commands or options, such as a
|
||||||
|
menu, a prominent item in the list meets this criterion.
|
||||||
|
|
||||||
|
1. Source Code.
|
||||||
|
|
||||||
|
The "source code" for a work means the preferred form of the work
|
||||||
|
for making modifications to it. "Object code" means any non-source
|
||||||
|
form of a work.
|
||||||
|
|
||||||
|
A "Standard Interface" means an interface that either is an official
|
||||||
|
standard defined by a recognized standards body, or, in the case of
|
||||||
|
interfaces specified for a particular programming language, one that
|
||||||
|
is widely used among developers working in that language.
|
||||||
|
|
||||||
|
The "System Libraries" of an executable work include anything, other
|
||||||
|
than the work as a whole, that (a) is included in the normal form of
|
||||||
|
packaging a Major Component, but which is not part of that Major
|
||||||
|
Component, and (b) serves only to enable use of the work with that
|
||||||
|
Major Component, or to implement a Standard Interface for which an
|
||||||
|
implementation is available to the public in source code form. A
|
||||||
|
"Major Component", in this context, means a major essential component
|
||||||
|
(kernel, window system, and so on) of the specific operating system
|
||||||
|
(if any) on which the executable work runs, or a compiler used to
|
||||||
|
produce the work, or an object code interpreter used to run it.
|
||||||
|
|
||||||
|
The "Corresponding Source" for a work in object code form means all
|
||||||
|
the source code needed to generate, install, and (for an executable
|
||||||
|
work) run the object code and to modify the work, including scripts to
|
||||||
|
control those activities. However, it does not include the work's
|
||||||
|
System Libraries, or general-purpose tools or generally available free
|
||||||
|
programs which are used unmodified in performing those activities but
|
||||||
|
which are not part of the work. For example, Corresponding Source
|
||||||
|
includes interface definition files associated with source files for
|
||||||
|
the work, and the source code for shared libraries and dynamically
|
||||||
|
linked subprograms that the work is specifically designed to require,
|
||||||
|
such as by intimate data communication or control flow between those
|
||||||
|
subprograms and other parts of the work.
|
||||||
|
|
||||||
|
The Corresponding Source need not include anything that users
|
||||||
|
can regenerate automatically from other parts of the Corresponding
|
||||||
|
Source.
|
||||||
|
|
||||||
|
The Corresponding Source for a work in source code form is that
|
||||||
|
same work.
|
||||||
|
|
||||||
|
2. Basic Permissions.
|
||||||
|
|
||||||
|
All rights granted under this License are granted for the term of
|
||||||
|
copyright on the Program, and are irrevocable provided the stated
|
||||||
|
conditions are met. This License explicitly affirms your unlimited
|
||||||
|
permission to run the unmodified Program. The output from running a
|
||||||
|
covered work is covered by this License only if the output, given its
|
||||||
|
content, constitutes a covered work. This License acknowledges your
|
||||||
|
rights of fair use or other equivalent, as provided by copyright law.
|
||||||
|
|
||||||
|
You may make, run and propagate covered works that you do not
|
||||||
|
convey, without conditions so long as your license otherwise remains
|
||||||
|
in force. You may convey covered works to others for the sole purpose
|
||||||
|
of having them make modifications exclusively for you, or provide you
|
||||||
|
with facilities for running those works, provided that you comply with
|
||||||
|
the terms of this License in conveying all material for which you do
|
||||||
|
not control copyright. Those thus making or running the covered works
|
||||||
|
for you must do so exclusively on your behalf, under your direction
|
||||||
|
and control, on terms that prohibit them from making any copies of
|
||||||
|
your copyrighted material outside their relationship with you.
|
||||||
|
|
||||||
|
Conveying under any other circumstances is permitted solely under
|
||||||
|
the conditions stated below. Sublicensing is not allowed; section 10
|
||||||
|
makes it unnecessary.
|
||||||
|
|
||||||
|
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||||
|
|
||||||
|
No covered work shall be deemed part of an effective technological
|
||||||
|
measure under any applicable law fulfilling obligations under article
|
||||||
|
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||||
|
similar laws prohibiting or restricting circumvention of such
|
||||||
|
measures.
|
||||||
|
|
||||||
|
When you convey a covered work, you waive any legal power to forbid
|
||||||
|
circumvention of technological measures to the extent such circumvention
|
||||||
|
is effected by exercising rights under this License with respect to
|
||||||
|
the covered work, and you disclaim any intention to limit operation or
|
||||||
|
modification of the work as a means of enforcing, against the work's
|
||||||
|
users, your or third parties' legal rights to forbid circumvention of
|
||||||
|
technological measures.
|
||||||
|
|
||||||
|
4. Conveying Verbatim Copies.
|
||||||
|
|
||||||
|
You may convey verbatim copies of the Program's source code as you
|
||||||
|
receive it, in any medium, provided that you conspicuously and
|
||||||
|
appropriately publish on each copy an appropriate copyright notice;
|
||||||
|
keep intact all notices stating that this License and any
|
||||||
|
non-permissive terms added in accord with section 7 apply to the code;
|
||||||
|
keep intact all notices of the absence of any warranty; and give all
|
||||||
|
recipients a copy of this License along with the Program.
|
||||||
|
|
||||||
|
You may charge any price or no price for each copy that you convey,
|
||||||
|
and you may offer support or warranty protection for a fee.
|
||||||
|
|
||||||
|
5. Conveying Modified Source Versions.
|
||||||
|
|
||||||
|
You may convey a work based on the Program, or the modifications to
|
||||||
|
produce it from the Program, in the form of source code under the
|
||||||
|
terms of section 4, provided that you also meet all of these conditions:
|
||||||
|
|
||||||
|
a) The work must carry prominent notices stating that you modified
|
||||||
|
it, and giving a relevant date.
|
||||||
|
|
||||||
|
b) The work must carry prominent notices stating that it is
|
||||||
|
released under this License and any conditions added under section
|
||||||
|
7. This requirement modifies the requirement in section 4 to
|
||||||
|
"keep intact all notices".
|
||||||
|
|
||||||
|
c) You must license the entire work, as a whole, under this
|
||||||
|
License to anyone who comes into possession of a copy. This
|
||||||
|
License will therefore apply, along with any applicable section 7
|
||||||
|
additional terms, to the whole of the work, and all its parts,
|
||||||
|
regardless of how they are packaged. This License gives no
|
||||||
|
permission to license the work in any other way, but it does not
|
||||||
|
invalidate such permission if you have separately received it.
|
||||||
|
|
||||||
|
d) If the work has interactive user interfaces, each must display
|
||||||
|
Appropriate Legal Notices; however, if the Program has interactive
|
||||||
|
interfaces that do not display Appropriate Legal Notices, your
|
||||||
|
work need not make them do so.
|
||||||
|
|
||||||
|
A compilation of a covered work with other separate and independent
|
||||||
|
works, which are not by their nature extensions of the covered work,
|
||||||
|
and which are not combined with it such as to form a larger program,
|
||||||
|
in or on a volume of a storage or distribution medium, is called an
|
||||||
|
"aggregate" if the compilation and its resulting copyright are not
|
||||||
|
used to limit the access or legal rights of the compilation's users
|
||||||
|
beyond what the individual works permit. Inclusion of a covered work
|
||||||
|
in an aggregate does not cause this License to apply to the other
|
||||||
|
parts of the aggregate.
|
||||||
|
|
||||||
|
6. Conveying Non-Source Forms.
|
||||||
|
|
||||||
|
You may convey a covered work in object code form under the terms
|
||||||
|
of sections 4 and 5, provided that you also convey the
|
||||||
|
machine-readable Corresponding Source under the terms of this License,
|
||||||
|
in one of these ways:
|
||||||
|
|
||||||
|
a) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by the
|
||||||
|
Corresponding Source fixed on a durable physical medium
|
||||||
|
customarily used for software interchange.
|
||||||
|
|
||||||
|
b) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by a
|
||||||
|
written offer, valid for at least three years and valid for as
|
||||||
|
long as you offer spare parts or customer support for that product
|
||||||
|
model, to give anyone who possesses the object code either (1) a
|
||||||
|
copy of the Corresponding Source for all the software in the
|
||||||
|
product that is covered by this License, on a durable physical
|
||||||
|
medium customarily used for software interchange, for a price no
|
||||||
|
more than your reasonable cost of physically performing this
|
||||||
|
conveying of source, or (2) access to copy the
|
||||||
|
Corresponding Source from a network server at no charge.
|
||||||
|
|
||||||
|
c) Convey individual copies of the object code with a copy of the
|
||||||
|
written offer to provide the Corresponding Source. This
|
||||||
|
alternative is allowed only occasionally and noncommercially, and
|
||||||
|
only if you received the object code with such an offer, in accord
|
||||||
|
with subsection 6b.
|
||||||
|
|
||||||
|
d) Convey the object code by offering access from a designated
|
||||||
|
place (gratis or for a charge), and offer equivalent access to the
|
||||||
|
Corresponding Source in the same way through the same place at no
|
||||||
|
further charge. You need not require recipients to copy the
|
||||||
|
Corresponding Source along with the object code. If the place to
|
||||||
|
copy the object code is a network server, the Corresponding Source
|
||||||
|
may be on a different server (operated by you or a third party)
|
||||||
|
that supports equivalent copying facilities, provided you maintain
|
||||||
|
clear directions next to the object code saying where to find the
|
||||||
|
Corresponding Source. Regardless of what server hosts the
|
||||||
|
Corresponding Source, you remain obligated to ensure that it is
|
||||||
|
available for as long as needed to satisfy these requirements.
|
||||||
|
|
||||||
|
e) Convey the object code using peer-to-peer transmission, provided
|
||||||
|
you inform other peers where the object code and Corresponding
|
||||||
|
Source of the work are being offered to the general public at no
|
||||||
|
charge under subsection 6d.
|
||||||
|
|
||||||
|
A separable portion of the object code, whose source code is excluded
|
||||||
|
from the Corresponding Source as a System Library, need not be
|
||||||
|
included in conveying the object code work.
|
||||||
|
|
||||||
|
A "User Product" is either (1) a "consumer product", which means any
|
||||||
|
tangible personal property which is normally used for personal, family,
|
||||||
|
or household purposes, or (2) anything designed or sold for incorporation
|
||||||
|
into a dwelling. In determining whether a product is a consumer product,
|
||||||
|
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||||
|
product received by a particular user, "normally used" refers to a
|
||||||
|
typical or common use of that class of product, regardless of the status
|
||||||
|
of the particular user or of the way in which the particular user
|
||||||
|
actually uses, or expects or is expected to use, the product. A product
|
||||||
|
is a consumer product regardless of whether the product has substantial
|
||||||
|
commercial, industrial or non-consumer uses, unless such uses represent
|
||||||
|
the only significant mode of use of the product.
|
||||||
|
|
||||||
|
"Installation Information" for a User Product means any methods,
|
||||||
|
procedures, authorization keys, or other information required to install
|
||||||
|
and execute modified versions of a covered work in that User Product from
|
||||||
|
a modified version of its Corresponding Source. The information must
|
||||||
|
suffice to ensure that the continued functioning of the modified object
|
||||||
|
code is in no case prevented or interfered with solely because
|
||||||
|
modification has been made.
|
||||||
|
|
||||||
|
If you convey an object code work under this section in, or with, or
|
||||||
|
specifically for use in, a User Product, and the conveying occurs as
|
||||||
|
part of a transaction in which the right of possession and use of the
|
||||||
|
User Product is transferred to the recipient in perpetuity or for a
|
||||||
|
fixed term (regardless of how the transaction is characterized), the
|
||||||
|
Corresponding Source conveyed under this section must be accompanied
|
||||||
|
by the Installation Information. But this requirement does not apply
|
||||||
|
if neither you nor any third party retains the ability to install
|
||||||
|
modified object code on the User Product (for example, the work has
|
||||||
|
been installed in ROM).
|
||||||
|
|
||||||
|
The requirement to provide Installation Information does not include a
|
||||||
|
requirement to continue to provide support service, warranty, or updates
|
||||||
|
for a work that has been modified or installed by the recipient, or for
|
||||||
|
the User Product in which it has been modified or installed. Access to a
|
||||||
|
network may be denied when the modification itself materially and
|
||||||
|
adversely affects the operation of the network or violates the rules and
|
||||||
|
protocols for communication across the network.
|
||||||
|
|
||||||
|
Corresponding Source conveyed, and Installation Information provided,
|
||||||
|
in accord with this section must be in a format that is publicly
|
||||||
|
documented (and with an implementation available to the public in
|
||||||
|
source code form), and must require no special password or key for
|
||||||
|
unpacking, reading or copying.
|
||||||
|
|
||||||
|
7. Additional Terms.
|
||||||
|
|
||||||
|
"Additional permissions" are terms that supplement the terms of this
|
||||||
|
License by making exceptions from one or more of its conditions.
|
||||||
|
Additional permissions that are applicable to the entire Program shall
|
||||||
|
be treated as though they were included in this License, to the extent
|
||||||
|
that they are valid under applicable law. If additional permissions
|
||||||
|
apply only to part of the Program, that part may be used separately
|
||||||
|
under those permissions, but the entire Program remains governed by
|
||||||
|
this License without regard to the additional permissions.
|
||||||
|
|
||||||
|
When you convey a copy of a covered work, you may at your option
|
||||||
|
remove any additional permissions from that copy, or from any part of
|
||||||
|
it. (Additional permissions may be written to require their own
|
||||||
|
removal in certain cases when you modify the work.) You may place
|
||||||
|
additional permissions on material, added by you to a covered work,
|
||||||
|
for which you have or can give appropriate copyright permission.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, for material you
|
||||||
|
add to a covered work, you may (if authorized by the copyright holders of
|
||||||
|
that material) supplement the terms of this License with terms:
|
||||||
|
|
||||||
|
a) Disclaiming warranty or limiting liability differently from the
|
||||||
|
terms of sections 15 and 16 of this License; or
|
||||||
|
|
||||||
|
b) Requiring preservation of specified reasonable legal notices or
|
||||||
|
author attributions in that material or in the Appropriate Legal
|
||||||
|
Notices displayed by works containing it; or
|
||||||
|
|
||||||
|
c) Prohibiting misrepresentation of the origin of that material, or
|
||||||
|
requiring that modified versions of such material be marked in
|
||||||
|
reasonable ways as different from the original version; or
|
||||||
|
|
||||||
|
d) Limiting the use for publicity purposes of names of licensors or
|
||||||
|
authors of the material; or
|
||||||
|
|
||||||
|
e) Declining to grant rights under trademark law for use of some
|
||||||
|
trade names, trademarks, or service marks; or
|
||||||
|
|
||||||
|
f) Requiring indemnification of licensors and authors of that
|
||||||
|
material by anyone who conveys the material (or modified versions of
|
||||||
|
it) with contractual assumptions of liability to the recipient, for
|
||||||
|
any liability that these contractual assumptions directly impose on
|
||||||
|
those licensors and authors.
|
||||||
|
|
||||||
|
All other non-permissive additional terms are considered "further
|
||||||
|
restrictions" within the meaning of section 10. If the Program as you
|
||||||
|
received it, or any part of it, contains a notice stating that it is
|
||||||
|
governed by this License along with a term that is a further
|
||||||
|
restriction, you may remove that term. If a license document contains
|
||||||
|
a further restriction but permits relicensing or conveying under this
|
||||||
|
License, you may add to a covered work material governed by the terms
|
||||||
|
of that license document, provided that the further restriction does
|
||||||
|
not survive such relicensing or conveying.
|
||||||
|
|
||||||
|
If you add terms to a covered work in accord with this section, you
|
||||||
|
must place, in the relevant source files, a statement of the
|
||||||
|
additional terms that apply to those files, or a notice indicating
|
||||||
|
where to find the applicable terms.
|
||||||
|
|
||||||
|
Additional terms, permissive or non-permissive, may be stated in the
|
||||||
|
form of a separately written license, or stated as exceptions;
|
||||||
|
the above requirements apply either way.
|
||||||
|
|
||||||
|
8. Termination.
|
||||||
|
|
||||||
|
You may not propagate or modify a covered work except as expressly
|
||||||
|
provided under this License. Any attempt otherwise to propagate or
|
||||||
|
modify it is void, and will automatically terminate your rights under
|
||||||
|
this License (including any patent licenses granted under the third
|
||||||
|
paragraph of section 11).
|
||||||
|
|
||||||
|
However, if you cease all violation of this License, then your
|
||||||
|
license from a particular copyright holder is reinstated (a)
|
||||||
|
provisionally, unless and until the copyright holder explicitly and
|
||||||
|
finally terminates your license, and (b) permanently, if the copyright
|
||||||
|
holder fails to notify you of the violation by some reasonable means
|
||||||
|
prior to 60 days after the cessation.
|
||||||
|
|
||||||
|
Moreover, your license from a particular copyright holder is
|
||||||
|
reinstated permanently if the copyright holder notifies you of the
|
||||||
|
violation by some reasonable means, this is the first time you have
|
||||||
|
received notice of violation of this License (for any work) from that
|
||||||
|
copyright holder, and you cure the violation prior to 30 days after
|
||||||
|
your receipt of the notice.
|
||||||
|
|
||||||
|
Termination of your rights under this section does not terminate the
|
||||||
|
licenses of parties who have received copies or rights from you under
|
||||||
|
this License. If your rights have been terminated and not permanently
|
||||||
|
reinstated, you do not qualify to receive new licenses for the same
|
||||||
|
material under section 10.
|
||||||
|
|
||||||
|
9. Acceptance Not Required for Having Copies.
|
||||||
|
|
||||||
|
You are not required to accept this License in order to receive or
|
||||||
|
run a copy of the Program. Ancillary propagation of a covered work
|
||||||
|
occurring solely as a consequence of using peer-to-peer transmission
|
||||||
|
to receive a copy likewise does not require acceptance. However,
|
||||||
|
nothing other than this License grants you permission to propagate or
|
||||||
|
modify any covered work. These actions infringe copyright if you do
|
||||||
|
not accept this License. Therefore, by modifying or propagating a
|
||||||
|
covered work, you indicate your acceptance of this License to do so.
|
||||||
|
|
||||||
|
10. Automatic Licensing of Downstream Recipients.
|
||||||
|
|
||||||
|
Each time you convey a covered work, the recipient automatically
|
||||||
|
receives a license from the original licensors, to run, modify and
|
||||||
|
propagate that work, subject to this License. You are not responsible
|
||||||
|
for enforcing compliance by third parties with this License.
|
||||||
|
|
||||||
|
An "entity transaction" is a transaction transferring control of an
|
||||||
|
organization, or substantially all assets of one, or subdividing an
|
||||||
|
organization, or merging organizations. If propagation of a covered
|
||||||
|
work results from an entity transaction, each party to that
|
||||||
|
transaction who receives a copy of the work also receives whatever
|
||||||
|
licenses to the work the party's predecessor in interest had or could
|
||||||
|
give under the previous paragraph, plus a right to possession of the
|
||||||
|
Corresponding Source of the work from the predecessor in interest, if
|
||||||
|
the predecessor has it or can get it with reasonable efforts.
|
||||||
|
|
||||||
|
You may not impose any further restrictions on the exercise of the
|
||||||
|
rights granted or affirmed under this License. For example, you may
|
||||||
|
not impose a license fee, royalty, or other charge for exercise of
|
||||||
|
rights granted under this License, and you may not initiate litigation
|
||||||
|
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||||
|
any patent claim is infringed by making, using, selling, offering for
|
||||||
|
sale, or importing the Program or any portion of it.
|
||||||
|
|
||||||
|
11. Patents.
|
||||||
|
|
||||||
|
A "contributor" is a copyright holder who authorizes use under this
|
||||||
|
License of the Program or a work on which the Program is based. The
|
||||||
|
work thus licensed is called the contributor's "contributor version".
|
||||||
|
|
||||||
|
A contributor's "essential patent claims" are all patent claims
|
||||||
|
owned or controlled by the contributor, whether already acquired or
|
||||||
|
hereafter acquired, that would be infringed by some manner, permitted
|
||||||
|
by this License, of making, using, or selling its contributor version,
|
||||||
|
but do not include claims that would be infringed only as a
|
||||||
|
consequence of further modification of the contributor version. For
|
||||||
|
purposes of this definition, "control" includes the right to grant
|
||||||
|
patent sublicenses in a manner consistent with the requirements of
|
||||||
|
this License.
|
||||||
|
|
||||||
|
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||||
|
patent license under the contributor's essential patent claims, to
|
||||||
|
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||||
|
propagate the contents of its contributor version.
|
||||||
|
|
||||||
|
In the following three paragraphs, a "patent license" is any express
|
||||||
|
agreement or commitment, however denominated, not to enforce a patent
|
||||||
|
(such as an express permission to practice a patent or covenant not to
|
||||||
|
sue for patent infringement). To "grant" such a patent license to a
|
||||||
|
party means to make such an agreement or commitment not to enforce a
|
||||||
|
patent against the party.
|
||||||
|
|
||||||
|
If you convey a covered work, knowingly relying on a patent license,
|
||||||
|
and the Corresponding Source of the work is not available for anyone
|
||||||
|
to copy, free of charge and under the terms of this License, through a
|
||||||
|
publicly available network server or other readily accessible means,
|
||||||
|
then you must either (1) cause the Corresponding Source to be so
|
||||||
|
available, or (2) arrange to deprive yourself of the benefit of the
|
||||||
|
patent license for this particular work, or (3) arrange, in a manner
|
||||||
|
consistent with the requirements of this License, to extend the patent
|
||||||
|
license to downstream recipients. "Knowingly relying" means you have
|
||||||
|
actual knowledge that, but for the patent license, your conveying the
|
||||||
|
covered work in a country, or your recipient's use of the covered work
|
||||||
|
in a country, would infringe one or more identifiable patents in that
|
||||||
|
country that you have reason to believe are valid.
|
||||||
|
|
||||||
|
If, pursuant to or in connection with a single transaction or
|
||||||
|
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||||
|
covered work, and grant a patent license to some of the parties
|
||||||
|
receiving the covered work authorizing them to use, propagate, modify
|
||||||
|
or convey a specific copy of the covered work, then the patent license
|
||||||
|
you grant is automatically extended to all recipients of the covered
|
||||||
|
work and works based on it.
|
||||||
|
|
||||||
|
A patent license is "discriminatory" if it does not include within
|
||||||
|
the scope of its coverage, prohibits the exercise of, or is
|
||||||
|
conditioned on the non-exercise of one or more of the rights that are
|
||||||
|
specifically granted under this License. You may not convey a covered
|
||||||
|
work if you are a party to an arrangement with a third party that is
|
||||||
|
in the business of distributing software, under which you make payment
|
||||||
|
to the third party based on the extent of your activity of conveying
|
||||||
|
the work, and under which the third party grants, to any of the
|
||||||
|
parties who would receive the covered work from you, a discriminatory
|
||||||
|
patent license (a) in connection with copies of the covered work
|
||||||
|
conveyed by you (or copies made from those copies), or (b) primarily
|
||||||
|
for and in connection with specific products or compilations that
|
||||||
|
contain the covered work, unless you entered into that arrangement,
|
||||||
|
or that patent license was granted, prior to 28 March 2007.
|
||||||
|
|
||||||
|
Nothing in this License shall be construed as excluding or limiting
|
||||||
|
any implied license or other defenses to infringement that may
|
||||||
|
otherwise be available to you under applicable patent law.
|
||||||
|
|
||||||
|
12. No Surrender of Others' Freedom.
|
||||||
|
|
||||||
|
If conditions are imposed on you (whether by court order, agreement or
|
||||||
|
otherwise) that contradict the conditions of this License, they do not
|
||||||
|
excuse you from the conditions of this License. If you cannot convey a
|
||||||
|
covered work so as to satisfy simultaneously your obligations under this
|
||||||
|
License and any other pertinent obligations, then as a consequence you may
|
||||||
|
not convey it at all. For example, if you agree to terms that obligate you
|
||||||
|
to collect a royalty for further conveying from those to whom you convey
|
||||||
|
the Program, the only way you could satisfy both those terms and this
|
||||||
|
License would be to refrain entirely from conveying the Program.
|
||||||
|
|
||||||
|
13. Use with the GNU Affero General Public License.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, you have
|
||||||
|
permission to link or combine any covered work with a work licensed
|
||||||
|
under version 3 of the GNU Affero General Public License into a single
|
||||||
|
combined work, and to convey the resulting work. The terms of this
|
||||||
|
License will continue to apply to the part which is the covered work,
|
||||||
|
but the special requirements of the GNU Affero General Public License,
|
||||||
|
section 13, concerning interaction through a network will apply to the
|
||||||
|
combination as such.
|
||||||
|
|
||||||
|
14. Revised Versions of this License.
|
||||||
|
|
||||||
|
The Free Software Foundation may publish revised and/or new versions of
|
||||||
|
the GNU General Public License from time to time. Such new versions will
|
||||||
|
be similar in spirit to the present version, but may differ in detail to
|
||||||
|
address new problems or concerns.
|
||||||
|
|
||||||
|
Each version is given a distinguishing version number. If the
|
||||||
|
Program specifies that a certain numbered version of the GNU General
|
||||||
|
Public License "or any later version" applies to it, you have the
|
||||||
|
option of following the terms and conditions either of that numbered
|
||||||
|
version or of any later version published by the Free Software
|
||||||
|
Foundation. If the Program does not specify a version number of the
|
||||||
|
GNU General Public License, you may choose any version ever published
|
||||||
|
by the Free Software Foundation.
|
||||||
|
|
||||||
|
If the Program specifies that a proxy can decide which future
|
||||||
|
versions of the GNU General Public License can be used, that proxy's
|
||||||
|
public statement of acceptance of a version permanently authorizes you
|
||||||
|
to choose that version for the Program.
|
||||||
|
|
||||||
|
Later license versions may give you additional or different
|
||||||
|
permissions. However, no additional obligations are imposed on any
|
||||||
|
author or copyright holder as a result of your choosing to follow a
|
||||||
|
later version.
|
||||||
|
|
||||||
|
15. Disclaimer of Warranty.
|
||||||
|
|
||||||
|
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||||
|
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||||
|
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||||
|
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||||
|
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||||
|
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||||
|
|
||||||
|
16. Limitation of Liability.
|
||||||
|
|
||||||
|
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||||
|
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||||
|
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||||
|
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||||
|
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||||
|
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||||
|
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||||
|
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||||
|
SUCH DAMAGES.
|
||||||
|
|
||||||
|
17. Interpretation of Sections 15 and 16.
|
||||||
|
|
||||||
|
If the disclaimer of warranty and limitation of liability provided
|
||||||
|
above cannot be given local legal effect according to their terms,
|
||||||
|
reviewing courts shall apply local law that most closely approximates
|
||||||
|
an absolute waiver of all civil liability in connection with the
|
||||||
|
Program, unless a warranty or assumption of liability accompanies a
|
||||||
|
copy of the Program in return for a fee.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
How to Apply These Terms to Your New Programs
|
||||||
|
|
||||||
|
If you develop a new program, and you want it to be of the greatest
|
||||||
|
possible use to the public, the best way to achieve this is to make it
|
||||||
|
free software which everyone can redistribute and change under these terms.
|
||||||
|
|
||||||
|
To do so, attach the following notices to the program. It is safest
|
||||||
|
to attach them to the start of each source file to most effectively
|
||||||
|
state the exclusion of warranty; and each file should have at least
|
||||||
|
the "copyright" line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
|
<one line to give the program's name and a brief idea of what it does.>
|
||||||
|
Copyright (C) <year> <name of author>
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
|
If the program does terminal interaction, make it output a short
|
||||||
|
notice like this when it starts in an interactive mode:
|
||||||
|
|
||||||
|
<program> Copyright (C) <year> <name of author>
|
||||||
|
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||||
|
This is free software, and you are welcome to redistribute it
|
||||||
|
under certain conditions; type `show c' for details.
|
||||||
|
|
||||||
|
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||||
|
parts of the General Public License. Of course, your program's commands
|
||||||
|
might be different; for a GUI interface, you would use an "about box".
|
||||||
|
|
||||||
|
You should also get your employer (if you work as a programmer) or school,
|
||||||
|
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||||
|
For more information on this, and how to apply and follow the GNU GPL, see
|
||||||
|
<https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
The GNU General Public License does not permit incorporating your program
|
||||||
|
into proprietary programs. If your program is a subroutine library, you
|
||||||
|
may consider it more useful to permit linking proprietary applications with
|
||||||
|
the library. If this is what you want to do, use the GNU Lesser General
|
||||||
|
Public License instead of this License. But first, please read
|
||||||
|
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
||||||
38
applications/external/mifare_nested/README.md
vendored
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
# Mifare Nested Attacks for Flipper Zero
|
||||||
|
|
||||||
|
Ported Nested attacks from Proxmark3 (Iceman fork)
|
||||||
|
|
||||||
|
This is not original Repo of this app! Please follow this link to find latest original source and support the author!
|
||||||
|
[Flipper (Mifare) Nested (by AloneLiberty)](https://github.com/AloneLiberty/FlipperNested)
|
||||||
|
|
||||||
|
## Currently supported attacks
|
||||||
|
|
||||||
|
- nested attack
|
||||||
|
- static nested attack
|
||||||
|
- hard nested attack
|
||||||
|
|
||||||
|
## Warning
|
||||||
|
|
||||||
|
App is still in early development, so there may be bugs. Your Flipper Zero may randomly crash/froze. Please create issue if you find any bugs (one bug = one issue). In original repo! - https://github.com/AloneLiberty/FlipperNested
|
||||||
|
|
||||||
|
## Disclaimer
|
||||||
|
|
||||||
|
The app provided for personal use only. Developer does not take responsibility for any loss or damage caused by the misuse of this app. In addition, the app developer does not guarantee the performance or compatibility of the app with all tags, and cannot be held liable for any damage caused to your tags/Flipper Zero as a result of using the app. By using this app you confirm that the tag belongs to you, you have permission to preform the attack and you agree to hold the app developer harmless from any and all claims, damages, or losses that may arise from its use.
|
||||||
|
|
||||||
|
## I need **your** help!
|
||||||
|
|
||||||
|
To successfuly recover keys from nested attack we need to correctly predict PRNG value. But we have a problem with that. Due to lack of my knowlege of Flipper Zero NFC HAL, PRNG can jump by quite large values (not like Proxmark3). So app is trying to find a delay where PRNG can be predicted accurately enough. This is not the best option, because we have to try to recover a bunch of unnecessary keys, which takes a lot of time and RAM and also spend a lot of time on timings. I don't know how to fix it.
|
||||||
|
|
||||||
|
UPD: Chameleon Ultra devs [faced same issue](https://youtu.be/_wfikmXNQzE?t=202). They seems to use same method: [nested.c](https://github.com/RfidResearchGroup/ChameleonUltra/blob/main/software/src/nested.c) (better know from the beginning of development...)
|
||||||
|
|
||||||
|
## How to use it?
|
||||||
|
|
||||||
|
Detailed guide: [EN](https://github.com/AloneLiberty/FlipperNested/wiki/Usage-guide), [RU](https://github.com/AloneLiberty/FlipperNested/wiki/%D0%93%D0%B0%D0%B9%D0%B4-%D0%BF%D0%BE-%D0%B8%D1%81%D0%BF%D0%BE%D0%BB%D1%8C%D0%B7%D0%BE%D0%B2%D0%B0%D0%BD%D0%B8%D1%8E).
|
||||||
|
|
||||||
|
## FAQ
|
||||||
|
|
||||||
|
For frequently asked questions, please refer to the FAQ: [EN](https://github.com/AloneLiberty/FlipperNested/wiki/FAQ), [RU](https://github.com/AloneLiberty/FlipperNested/wiki/%D0%A7%D0%90%D0%92%D0%9E).
|
||||||
|
|
||||||
|
## Contacts
|
||||||
|
|
||||||
|
Find here: https://github.com/AloneLiberty/FlipperNested
|
||||||
3
applications/external/mifare_nested/TODO.md
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# TODO:
|
||||||
|
|
||||||
|
1. Better (faster) detection of delay in a nested attack
|
||||||
25
applications/external/mifare_nested/application.fam
vendored
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
App(
|
||||||
|
appid="mifare_nested",
|
||||||
|
name="Mifare Nested",
|
||||||
|
apptype=FlipperAppType.EXTERNAL,
|
||||||
|
entry_point="mifare_nested_app",
|
||||||
|
requires=[
|
||||||
|
"storage",
|
||||||
|
"gui",
|
||||||
|
"nfc"
|
||||||
|
],
|
||||||
|
stack_size=4 * 1024,
|
||||||
|
order=30,
|
||||||
|
fap_icon="assets/icon.png",
|
||||||
|
fap_category="NFC",
|
||||||
|
fap_private_libs=[
|
||||||
|
Lib(name="nested"),
|
||||||
|
Lib(name="parity"),
|
||||||
|
Lib(name="crypto1")
|
||||||
|
],
|
||||||
|
fap_icon_assets="assets",
|
||||||
|
fap_author="AloneLiberty",
|
||||||
|
fap_description="Recover Mifare Classic keys",
|
||||||
|
fap_weburl="https://github.com/AloneLiberty/FlipperNested",
|
||||||
|
fap_version=(1, 4)
|
||||||
|
)
|
||||||
BIN
applications/external/mifare_nested/assets/ApplyTag.png
vendored
Normal file
|
After Width: | Height: | Size: 3.7 KiB |
BIN
applications/external/mifare_nested/assets/DolphinCry.png
vendored
Normal file
|
After Width: | Height: | Size: 3.8 KiB |
BIN
applications/external/mifare_nested/assets/DolphinSuccess.png
vendored
Normal file
|
After Width: | Height: | Size: 2.6 KiB |
BIN
applications/external/mifare_nested/assets/Loading.png
vendored
Normal file
|
After Width: | Height: | Size: 3.6 KiB |
BIN
applications/external/mifare_nested/assets/icon.png
vendored
Normal file
|
After Width: | Height: | Size: 145 B |
118
applications/external/mifare_nested/lib/crypto1/crypto1.c
vendored
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
#include "crypto1.h"
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
void crypto1_reset(Crypto1* crypto1) {
|
||||||
|
furi_assert(crypto1);
|
||||||
|
crypto1->even = 0;
|
||||||
|
crypto1->odd = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void crypto1_init(Crypto1* crypto1, uint64_t key) {
|
||||||
|
furi_assert(crypto1);
|
||||||
|
crypto1->even = 0;
|
||||||
|
crypto1->odd = 0;
|
||||||
|
for(int8_t i = 47; i > 0; i -= 2) {
|
||||||
|
crypto1->odd = crypto1->odd << 1 | FURI_BIT(key, (i - 1) ^ 7);
|
||||||
|
crypto1->even = crypto1->even << 1 | FURI_BIT(key, i ^ 7);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t crypto1_filter(uint32_t in) {
|
||||||
|
uint32_t out = 0;
|
||||||
|
out = 0xf22c0 >> (in & 0xf) & 16;
|
||||||
|
out |= 0x6c9c0 >> (in >> 4 & 0xf) & 8;
|
||||||
|
out |= 0x3c8b0 >> (in >> 8 & 0xf) & 4;
|
||||||
|
out |= 0x1e458 >> (in >> 12 & 0xf) & 2;
|
||||||
|
out |= 0x0d938 >> (in >> 16 & 0xf) & 1;
|
||||||
|
return FURI_BIT(0xEC57E80A, out);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t crypto1_bit(Crypto1* crypto1, uint8_t in, int is_encrypted) {
|
||||||
|
furi_assert(crypto1);
|
||||||
|
uint8_t out = crypto1_filter(crypto1->odd);
|
||||||
|
uint32_t feed = out & (!!is_encrypted);
|
||||||
|
feed ^= !!in;
|
||||||
|
feed ^= LF_POLY_ODD & crypto1->odd;
|
||||||
|
feed ^= LF_POLY_EVEN & crypto1->even;
|
||||||
|
crypto1->even = crypto1->even << 1 | (evenparity32(feed));
|
||||||
|
|
||||||
|
FURI_SWAP(crypto1->odd, crypto1->even);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t crypto1_byte(Crypto1* crypto1, uint8_t in, int is_encrypted) {
|
||||||
|
furi_assert(crypto1);
|
||||||
|
uint8_t out = 0;
|
||||||
|
for(uint8_t i = 0; i < 8; i++) {
|
||||||
|
out |= crypto1_bit(crypto1, FURI_BIT(in, i), is_encrypted) << i;
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t crypto1_word(Crypto1* crypto1, uint32_t in, int is_encrypted) {
|
||||||
|
furi_assert(crypto1);
|
||||||
|
uint32_t out = 0;
|
||||||
|
for(uint8_t i = 0; i < 32; i++) {
|
||||||
|
out |= (uint32_t)crypto1_bit(crypto1, BEBIT(in, i), is_encrypted) << (24 ^ i);
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t prng_successor(uint32_t x, uint32_t n) {
|
||||||
|
SWAPENDIAN(x);
|
||||||
|
while(n--) x = x >> 1 | (x >> 16 ^ x >> 18 ^ x >> 19 ^ x >> 21) << 31;
|
||||||
|
|
||||||
|
return SWAPENDIAN(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
void crypto1_decrypt(
|
||||||
|
Crypto1* crypto,
|
||||||
|
uint8_t* encrypted_data,
|
||||||
|
uint16_t encrypted_data_bits,
|
||||||
|
uint8_t* decrypted_data) {
|
||||||
|
furi_assert(crypto);
|
||||||
|
furi_assert(encrypted_data);
|
||||||
|
furi_assert(decrypted_data);
|
||||||
|
|
||||||
|
if(encrypted_data_bits < 8) {
|
||||||
|
uint8_t decrypted_byte = 0;
|
||||||
|
decrypted_byte |= (crypto1_bit(crypto, 0, 0) ^ FURI_BIT(encrypted_data[0], 0)) << 0;
|
||||||
|
decrypted_byte |= (crypto1_bit(crypto, 0, 0) ^ FURI_BIT(encrypted_data[0], 1)) << 1;
|
||||||
|
decrypted_byte |= (crypto1_bit(crypto, 0, 0) ^ FURI_BIT(encrypted_data[0], 2)) << 2;
|
||||||
|
decrypted_byte |= (crypto1_bit(crypto, 0, 0) ^ FURI_BIT(encrypted_data[0], 3)) << 3;
|
||||||
|
decrypted_data[0] = decrypted_byte;
|
||||||
|
} else {
|
||||||
|
for(size_t i = 0; i < encrypted_data_bits / 8; i++) {
|
||||||
|
decrypted_data[i] = crypto1_byte(crypto, 0, 0) ^ encrypted_data[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void crypto1_encrypt(
|
||||||
|
Crypto1* crypto,
|
||||||
|
uint8_t* keystream,
|
||||||
|
uint8_t* plain_data,
|
||||||
|
uint16_t plain_data_bits,
|
||||||
|
uint8_t* encrypted_data,
|
||||||
|
uint8_t* encrypted_parity) {
|
||||||
|
furi_assert(crypto);
|
||||||
|
furi_assert(plain_data);
|
||||||
|
furi_assert(encrypted_data);
|
||||||
|
furi_assert(encrypted_parity);
|
||||||
|
|
||||||
|
if(plain_data_bits < 8) {
|
||||||
|
encrypted_data[0] = 0;
|
||||||
|
for(size_t i = 0; i < plain_data_bits; i++) {
|
||||||
|
encrypted_data[0] |= (crypto1_bit(crypto, 0, 0) ^ FURI_BIT(plain_data[0], i)) << i;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
memset(encrypted_parity, 0, plain_data_bits / 8 + 1);
|
||||||
|
for(uint8_t i = 0; i < plain_data_bits / 8; i++) {
|
||||||
|
encrypted_data[i] = crypto1_byte(crypto, keystream ? keystream[i] : 0, 0) ^
|
||||||
|
plain_data[i];
|
||||||
|
encrypted_parity[i / 8] |=
|
||||||
|
(((crypto1_filter(crypto->odd) ^ oddparity8(plain_data[i])) & 0x01)
|
||||||
|
<< (7 - (i & 0x0007)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
39
applications/external/mifare_nested/lib/crypto1/crypto1.h
vendored
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
#include "../../lib/parity/parity.h"
|
||||||
|
#include <lib/nfc/protocols/mifare_classic.h>
|
||||||
|
#include <lib/nfc/protocols/crypto1.h>
|
||||||
|
#include "stddef.h"
|
||||||
|
|
||||||
|
#define LF_POLY_ODD (0x29CE5C)
|
||||||
|
#define LF_POLY_EVEN (0x870804)
|
||||||
|
|
||||||
|
#define SWAPENDIAN(x) \
|
||||||
|
((x) = ((x) >> 8 & 0xff00ff) | ((x)&0xff00ff) << 8, (x) = (x) >> 16 | (x) << 16)
|
||||||
|
#define BEBIT(x, n) FURI_BIT(x, (n) ^ 24)
|
||||||
|
|
||||||
|
void crypto1_reset(Crypto1* crypto1);
|
||||||
|
|
||||||
|
void crypto1_init(Crypto1* crypto1, uint64_t key);
|
||||||
|
|
||||||
|
uint32_t crypto1_filter(uint32_t in);
|
||||||
|
|
||||||
|
uint8_t crypto1_bit(Crypto1* crypto1, uint8_t in, int is_encrypted);
|
||||||
|
|
||||||
|
uint8_t crypto1_byte(Crypto1* crypto1, uint8_t in, int is_encrypted);
|
||||||
|
|
||||||
|
uint32_t crypto1_word(Crypto1* crypto1, uint32_t in, int is_encrypted);
|
||||||
|
|
||||||
|
uint32_t prng_successor(uint32_t x, uint32_t n);
|
||||||
|
|
||||||
|
void crypto1_decrypt(
|
||||||
|
Crypto1* crypto,
|
||||||
|
uint8_t* encrypted_data,
|
||||||
|
uint16_t encrypted_data_bits,
|
||||||
|
uint8_t* decrypted_data);
|
||||||
|
|
||||||
|
void crypto1_encrypt(
|
||||||
|
Crypto1* crypto,
|
||||||
|
uint8_t* keystream,
|
||||||
|
uint8_t* plain_data,
|
||||||
|
uint16_t plain_data_bits,
|
||||||
|
uint8_t* encrypted_data,
|
||||||
|
uint8_t* encrypted_parity);
|
||||||
740
applications/external/mifare_nested/lib/nested/nested.c
vendored
Normal file
@@ -0,0 +1,740 @@
|
|||||||
|
#include "nested.h"
|
||||||
|
|
||||||
|
#include <furi_hal_nfc.h>
|
||||||
|
#include "../../lib/parity/parity.h"
|
||||||
|
#include "../../lib/crypto1/crypto1.h"
|
||||||
|
#define TAG "Nested"
|
||||||
|
|
||||||
|
void nfc_util_num2bytes(uint64_t src, uint8_t len, uint8_t* dest) {
|
||||||
|
furi_assert(dest);
|
||||||
|
furi_assert(len <= 8);
|
||||||
|
|
||||||
|
while(len--) {
|
||||||
|
dest[len] = (uint8_t)src;
|
||||||
|
src >>= 8;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t nfc_util_bytes2num(const uint8_t* src, uint8_t len) {
|
||||||
|
furi_assert(src);
|
||||||
|
furi_assert(len <= 8);
|
||||||
|
|
||||||
|
uint64_t res = 0;
|
||||||
|
while(len--) {
|
||||||
|
res = (res << 8) | (*src);
|
||||||
|
src++;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t nfca_get_crc16(uint8_t* buff, uint16_t len) {
|
||||||
|
uint16_t crc = 0x6363; // NFCA_CRC_INIT
|
||||||
|
uint8_t byte = 0;
|
||||||
|
|
||||||
|
for(uint8_t i = 0; i < len; i++) {
|
||||||
|
byte = buff[i];
|
||||||
|
byte ^= (uint8_t)(crc & 0xff);
|
||||||
|
byte ^= byte << 4;
|
||||||
|
crc = (crc >> 8) ^ (((uint16_t)byte) << 8) ^ (((uint16_t)byte) << 3) ^
|
||||||
|
(((uint16_t)byte) >> 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
return crc;
|
||||||
|
}
|
||||||
|
|
||||||
|
void nfca_append_crc16(uint8_t* buff, uint16_t len) {
|
||||||
|
uint16_t crc = nfca_get_crc16(buff, len);
|
||||||
|
buff[len] = (uint8_t)crc;
|
||||||
|
buff[len + 1] = (uint8_t)(crc >> 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool mifare_sendcmd_short(
|
||||||
|
Crypto1* crypto,
|
||||||
|
FuriHalNfcTxRxContext* tx_rx,
|
||||||
|
bool crypted,
|
||||||
|
uint32_t cmd,
|
||||||
|
uint32_t data) {
|
||||||
|
uint16_t pos;
|
||||||
|
uint8_t dcmd[4] = {cmd, data, 0x00, 0x00};
|
||||||
|
nfca_append_crc16(dcmd, 2);
|
||||||
|
|
||||||
|
memset(tx_rx->tx_data, 0, sizeof(tx_rx->tx_data));
|
||||||
|
memset(tx_rx->tx_parity, 0, sizeof(tx_rx->tx_parity));
|
||||||
|
|
||||||
|
if(crypted) {
|
||||||
|
for(pos = 0; pos < 4; pos++) {
|
||||||
|
uint8_t res = crypto1_byte(crypto, 0x00, 0) ^ dcmd[pos];
|
||||||
|
tx_rx->tx_data[pos] = res;
|
||||||
|
tx_rx->tx_parity[0] |=
|
||||||
|
(((crypto1_filter(crypto->odd) ^ oddparity8(dcmd[pos])) & 0x01) << (7 - pos));
|
||||||
|
}
|
||||||
|
|
||||||
|
tx_rx->tx_rx_type = FuriHalNfcTxRxTypeRaw;
|
||||||
|
tx_rx->tx_bits = 4 * 8;
|
||||||
|
} else {
|
||||||
|
for(pos = 0; pos < 2; pos++) {
|
||||||
|
tx_rx->tx_data[pos] = dcmd[pos];
|
||||||
|
}
|
||||||
|
|
||||||
|
tx_rx->tx_rx_type = FuriHalNfcTxRxTypeRxNoCrc;
|
||||||
|
tx_rx->tx_bits = 2 * 8;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!furi_hal_nfc_tx_rx(tx_rx, 6)) return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool mifare_classic_authex(
|
||||||
|
Crypto1* crypto,
|
||||||
|
FuriHalNfcTxRxContext* tx_rx,
|
||||||
|
uint32_t uid,
|
||||||
|
uint32_t blockNo,
|
||||||
|
uint32_t keyType,
|
||||||
|
uint64_t ui64Key,
|
||||||
|
bool isNested,
|
||||||
|
uint32_t* ntptr) {
|
||||||
|
uint32_t nt, ntpp; // Supplied tag nonce
|
||||||
|
uint8_t nr[4];
|
||||||
|
|
||||||
|
// "random" reader nonce:
|
||||||
|
nfc_util_num2bytes(prng_successor(0, 32), 4, nr); // DWT->CYCCNT
|
||||||
|
|
||||||
|
// Transmit MIFARE_CLASSIC_AUTH
|
||||||
|
if(!mifare_sendcmd_short(crypto, tx_rx, isNested, 0x60 + (keyType & 0x01), blockNo)) {
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
memset(tx_rx->tx_data, 0, sizeof(tx_rx->tx_data));
|
||||||
|
memset(tx_rx->tx_parity, 0, sizeof(tx_rx->tx_parity));
|
||||||
|
|
||||||
|
nt = (uint32_t)nfc_util_bytes2num(tx_rx->rx_data, 4);
|
||||||
|
|
||||||
|
if(isNested) crypto1_reset(crypto); // deinit
|
||||||
|
|
||||||
|
crypto1_init(crypto, ui64Key);
|
||||||
|
|
||||||
|
if(isNested) {
|
||||||
|
nt = crypto1_word(crypto, nt ^ uid, 1) ^ nt;
|
||||||
|
} else {
|
||||||
|
crypto1_word(crypto, nt ^ uid, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// save Nt
|
||||||
|
if(ntptr) *ntptr = nt;
|
||||||
|
|
||||||
|
// Generate (encrypted) nr+parity by loading it into the cipher (Nr)
|
||||||
|
tx_rx->tx_parity[0] = 0;
|
||||||
|
for(uint8_t i = 0; i < 4; i++) {
|
||||||
|
tx_rx->tx_data[i] = crypto1_byte(crypto, nr[i], 0) ^ nr[i];
|
||||||
|
tx_rx->tx_parity[0] |=
|
||||||
|
(((crypto1_filter(crypto->odd) ^ oddparity8(nr[i])) & 0x01) << (7 - i));
|
||||||
|
}
|
||||||
|
|
||||||
|
nt = prng_successor(nt, 32);
|
||||||
|
|
||||||
|
for(uint8_t i = 4; i < 8; i++) {
|
||||||
|
nt = prng_successor(nt, 8);
|
||||||
|
tx_rx->tx_data[i] = crypto1_byte(crypto, 0x00, 0) ^ (nt & 0xff);
|
||||||
|
tx_rx->tx_parity[0] |=
|
||||||
|
(((crypto1_filter(crypto->odd) ^ oddparity8(nt & 0xff)) & 0x01) << (7 - i));
|
||||||
|
}
|
||||||
|
|
||||||
|
tx_rx->tx_rx_type = FuriHalNfcTxRxTypeRaw;
|
||||||
|
tx_rx->tx_bits = 8 * 8;
|
||||||
|
|
||||||
|
if(!furi_hal_nfc_tx_rx(tx_rx, 25)) {
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
uint32_t answer = (uint32_t)nfc_util_bytes2num(tx_rx->rx_data, 4);
|
||||||
|
|
||||||
|
ntpp = prng_successor(nt, 32) ^ crypto1_word(crypto, 0, 0);
|
||||||
|
|
||||||
|
if(answer != ntpp) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int valid_nonce(uint32_t Nt, uint32_t NtEnc, uint32_t Ks1, const uint8_t* parity) {
|
||||||
|
return ((oddparity8((Nt >> 24) & 0xFF) ==
|
||||||
|
((parity[0]) ^ oddparity8((NtEnc >> 24) & 0xFF) ^ FURI_BIT(Ks1, 16))) &&
|
||||||
|
(oddparity8((Nt >> 16) & 0xFF) ==
|
||||||
|
((parity[1]) ^ oddparity8((NtEnc >> 16) & 0xFF) ^ FURI_BIT(Ks1, 8))) &&
|
||||||
|
(oddparity8((Nt >> 8) & 0xFF) ==
|
||||||
|
((parity[2]) ^ oddparity8((NtEnc >> 8) & 0xFF) ^ FURI_BIT(Ks1, 0)))) ?
|
||||||
|
1 :
|
||||||
|
0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void nonce_distance(uint32_t* msb, uint32_t* lsb) {
|
||||||
|
uint16_t x = 1, pos;
|
||||||
|
uint8_t calc_ok = 0;
|
||||||
|
|
||||||
|
for(uint16_t i = 1; i; ++i) {
|
||||||
|
pos = (x & 0xff) << 8 | x >> 8;
|
||||||
|
|
||||||
|
if((pos == *msb) & !(calc_ok >> 0 & 0x01)) {
|
||||||
|
*msb = i;
|
||||||
|
calc_ok |= 0x01;
|
||||||
|
}
|
||||||
|
|
||||||
|
if((pos == *lsb) & !(calc_ok >> 1 & 0x01)) {
|
||||||
|
*lsb = i;
|
||||||
|
calc_ok |= 0x02;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(calc_ok == 0x03) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
x = x >> 1 | (x ^ x >> 2 ^ x >> 3 ^ x >> 5) << 15;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool validate_prng_nonce(uint32_t nonce) {
|
||||||
|
uint32_t msb = nonce >> 16;
|
||||||
|
uint32_t lsb = nonce & 0xffff;
|
||||||
|
nonce_distance(&msb, &lsb);
|
||||||
|
return ((65535 - msb + lsb) % 65535) == 16;
|
||||||
|
}
|
||||||
|
|
||||||
|
MifareNestedNonceType nested_check_nonce_type(FuriHalNfcTxRxContext* tx_rx, uint8_t blockNo) {
|
||||||
|
uint32_t nonces[5] = {};
|
||||||
|
uint8_t sameNonces = 0;
|
||||||
|
uint8_t hardNonces = 0;
|
||||||
|
Crypto1 crypt;
|
||||||
|
Crypto1* crypto = {&crypt};
|
||||||
|
|
||||||
|
for(int32_t i = 0; i < 5; i++) {
|
||||||
|
// Setup nfc poller
|
||||||
|
nfc_activate();
|
||||||
|
furi_hal_nfc_activate_nfca(100, NULL);
|
||||||
|
|
||||||
|
// Start communication
|
||||||
|
bool success = mifare_sendcmd_short(crypto, tx_rx, false, 0x60, blockNo);
|
||||||
|
if(!success) {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
|
||||||
|
uint32_t nt = (uint32_t)nfc_util_bytes2num(tx_rx->rx_data, 4);
|
||||||
|
if(nt == 0) continue;
|
||||||
|
if(!validate_prng_nonce(nt)) hardNonces++;
|
||||||
|
nonces[i] = nt;
|
||||||
|
|
||||||
|
nfc_deactivate();
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int32_t i = 0; i < 5; i++) {
|
||||||
|
for(int32_t j = 0; j < 5; j++) {
|
||||||
|
if(i != j && nonces[j] && nonces[i] == nonces[j]) {
|
||||||
|
sameNonces++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!nonces[4]) {
|
||||||
|
return MifareNestedNonceNoTag;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(sameNonces > 3) {
|
||||||
|
return MifareNestedNonceStatic;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(hardNonces > 3) {
|
||||||
|
return MifareNestedNonceHard;
|
||||||
|
}
|
||||||
|
|
||||||
|
return MifareNestedNonceWeak;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct nonce_info_static nested_static_nonce_attack(
|
||||||
|
FuriHalNfcTxRxContext* tx_rx,
|
||||||
|
uint8_t blockNo,
|
||||||
|
uint8_t keyType,
|
||||||
|
uint8_t targetBlockNo,
|
||||||
|
uint8_t targetKeyType,
|
||||||
|
uint64_t ui64Key) {
|
||||||
|
uint32_t cuid = 0;
|
||||||
|
Crypto1* crypto = malloc(sizeof(Crypto1));
|
||||||
|
struct nonce_info_static r;
|
||||||
|
|
||||||
|
r.full = false;
|
||||||
|
|
||||||
|
// Setup nfc poller
|
||||||
|
nfc_activate();
|
||||||
|
if(!furi_hal_nfc_activate_nfca(200, &cuid)) {
|
||||||
|
free(crypto);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
r.cuid = cuid;
|
||||||
|
|
||||||
|
uint32_t nt1;
|
||||||
|
uint32_t nt_unused;
|
||||||
|
|
||||||
|
crypto1_reset(crypto);
|
||||||
|
|
||||||
|
mifare_classic_authex(crypto, tx_rx, cuid, blockNo, keyType, ui64Key, false, &nt1);
|
||||||
|
|
||||||
|
if(targetKeyType == 1 && nt1 == 0x009080A2) {
|
||||||
|
r.target_nt[0] = prng_successor(nt1, 161);
|
||||||
|
r.target_nt[1] = prng_successor(nt1, 321);
|
||||||
|
} else {
|
||||||
|
r.target_nt[0] = prng_successor(nt1, 160);
|
||||||
|
r.target_nt[1] = prng_successor(nt1, 320);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool success =
|
||||||
|
mifare_sendcmd_short(crypto, tx_rx, true, 0x60 + (targetKeyType & 0x01), targetBlockNo);
|
||||||
|
|
||||||
|
if(!success) {
|
||||||
|
free(crypto);
|
||||||
|
return r;
|
||||||
|
};
|
||||||
|
|
||||||
|
uint32_t nt2 = nfc_util_bytes2num(tx_rx->rx_data, 4);
|
||||||
|
r.target_ks[0] = nt2 ^ r.target_nt[0];
|
||||||
|
|
||||||
|
nfc_activate();
|
||||||
|
|
||||||
|
if(!furi_hal_nfc_activate_nfca(200, &cuid)) {
|
||||||
|
free(crypto);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
crypto1_reset(crypto);
|
||||||
|
|
||||||
|
mifare_classic_authex(crypto, tx_rx, cuid, blockNo, keyType, ui64Key, false, &nt1);
|
||||||
|
|
||||||
|
mifare_classic_authex(crypto, tx_rx, cuid, blockNo, keyType, ui64Key, true, &nt_unused);
|
||||||
|
|
||||||
|
success =
|
||||||
|
mifare_sendcmd_short(crypto, tx_rx, true, 0x60 + (targetKeyType & 0x01), targetBlockNo);
|
||||||
|
|
||||||
|
free(crypto);
|
||||||
|
|
||||||
|
if(!success) {
|
||||||
|
return r;
|
||||||
|
};
|
||||||
|
|
||||||
|
uint32_t nt3 = (uint32_t)nfc_util_bytes2num(tx_rx->rx_data, 4);
|
||||||
|
|
||||||
|
r.target_ks[1] = nt3 ^ r.target_nt[1];
|
||||||
|
r.full = true;
|
||||||
|
|
||||||
|
nfc_deactivate();
|
||||||
|
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t nested_calibrate_distance(
|
||||||
|
FuriHalNfcTxRxContext* tx_rx,
|
||||||
|
uint8_t blockNo,
|
||||||
|
uint8_t keyType,
|
||||||
|
uint64_t ui64Key,
|
||||||
|
uint32_t delay,
|
||||||
|
bool full) {
|
||||||
|
uint32_t cuid = 0;
|
||||||
|
Crypto1* crypto = malloc(sizeof(Crypto1));
|
||||||
|
uint32_t nt1, nt2, i = 0, davg = 0, dmin = 0, dmax = 0, rtr = 0, unsuccessful_tries = 0;
|
||||||
|
uint32_t max_prng_value = full ? 65565 : 1200;
|
||||||
|
uint32_t rounds = full ? 5 : 17; // full does not require precision
|
||||||
|
uint32_t collected = 0;
|
||||||
|
|
||||||
|
for(rtr = 0; rtr < rounds; rtr++) {
|
||||||
|
nfc_activate();
|
||||||
|
if(!furi_hal_nfc_activate_nfca(200, &cuid)) break;
|
||||||
|
|
||||||
|
if(!mifare_classic_authex(crypto, tx_rx, cuid, blockNo, keyType, ui64Key, false, &nt1)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
furi_delay_us(delay);
|
||||||
|
|
||||||
|
if(!mifare_classic_authex(crypto, tx_rx, cuid, blockNo, keyType, ui64Key, true, &nt2)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// NXP Mifare is typical around 840, but for some unlicensed/compatible mifare tag this can be 160
|
||||||
|
uint32_t nttmp = prng_successor(nt1, 100);
|
||||||
|
|
||||||
|
for(i = 101; i < max_prng_value; i++) {
|
||||||
|
nttmp = prng_successor(nttmp, 1);
|
||||||
|
if(nttmp == nt2) break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(i != max_prng_value) {
|
||||||
|
if(rtr != 0) {
|
||||||
|
davg += i;
|
||||||
|
dmin = MIN(dmin, i);
|
||||||
|
dmax = MAX(dmax, i);
|
||||||
|
} else {
|
||||||
|
dmin = dmax = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
FURI_LOG_D(TAG, "Calibrating: ntdist=%lu", i);
|
||||||
|
collected++;
|
||||||
|
} else {
|
||||||
|
unsuccessful_tries++;
|
||||||
|
if(unsuccessful_tries > 12) {
|
||||||
|
free(crypto);
|
||||||
|
FURI_LOG_E(
|
||||||
|
TAG,
|
||||||
|
"Tag isn't vulnerable to nested attack (random numbers are not predictable)");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(collected > 1) davg = (davg + (collected - 1) / 2) / (collected - 1);
|
||||||
|
|
||||||
|
davg = MIN(MAX(dmin, davg), dmax);
|
||||||
|
|
||||||
|
FURI_LOG_I(
|
||||||
|
TAG,
|
||||||
|
"Calibration completed: rtr=%lu min=%lu max=%lu avg=%lu collected=%lu",
|
||||||
|
rtr,
|
||||||
|
dmin,
|
||||||
|
dmax,
|
||||||
|
davg,
|
||||||
|
collected);
|
||||||
|
|
||||||
|
free(crypto);
|
||||||
|
|
||||||
|
nfc_deactivate();
|
||||||
|
|
||||||
|
return davg;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct distance_info nested_calibrate_distance_info(
|
||||||
|
FuriHalNfcTxRxContext* tx_rx,
|
||||||
|
uint8_t blockNo,
|
||||||
|
uint8_t keyType,
|
||||||
|
uint64_t ui64Key) {
|
||||||
|
uint32_t cuid = 0;
|
||||||
|
Crypto1* crypto = malloc(sizeof(Crypto1));
|
||||||
|
uint32_t nt1, nt2, i = 0, davg = 0, dmin = 0, dmax = 0, rtr = 0, unsuccessful_tries = 0;
|
||||||
|
struct distance_info r;
|
||||||
|
r.min_prng = 0;
|
||||||
|
r.max_prng = 0;
|
||||||
|
r.mid_prng = 0;
|
||||||
|
|
||||||
|
for(rtr = 0; rtr < 10; rtr++) {
|
||||||
|
nfc_activate();
|
||||||
|
if(!furi_hal_nfc_activate_nfca(200, &cuid)) break;
|
||||||
|
|
||||||
|
mifare_classic_authex(crypto, tx_rx, cuid, blockNo, keyType, ui64Key, false, &nt1);
|
||||||
|
|
||||||
|
mifare_classic_authex(crypto, tx_rx, cuid, blockNo, keyType, ui64Key, true, &nt2);
|
||||||
|
|
||||||
|
// NXP Mifare is typical around 840, but for some unlicensed/compatible mifare tag this can be 160
|
||||||
|
uint32_t nttmp = prng_successor(nt1, 1);
|
||||||
|
|
||||||
|
for(i = 2; i < 65565; i++) {
|
||||||
|
nttmp = prng_successor(nttmp, 1);
|
||||||
|
if(nttmp == nt2) break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(i != 65565) {
|
||||||
|
if(rtr != 0) {
|
||||||
|
davg += i;
|
||||||
|
if(dmin == 0) {
|
||||||
|
dmin = i;
|
||||||
|
} else {
|
||||||
|
dmin = MIN(dmin, i);
|
||||||
|
}
|
||||||
|
dmax = MAX(dmax, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
FURI_LOG_D(TAG, "Calibrating: ntdist=%lu", i);
|
||||||
|
} else {
|
||||||
|
unsuccessful_tries++;
|
||||||
|
if(unsuccessful_tries > 12) {
|
||||||
|
free(crypto);
|
||||||
|
|
||||||
|
FURI_LOG_E(
|
||||||
|
TAG,
|
||||||
|
"Tag isn't vulnerable to nested attack (random numbers are not predictable)");
|
||||||
|
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(rtr > 1) davg = (davg + (rtr - 1) / 2) / (rtr - 1);
|
||||||
|
|
||||||
|
FURI_LOG_I(
|
||||||
|
TAG, "Calibration completed: rtr=%lu min=%lu max=%lu avg=%lu", rtr, dmin, dmax, davg);
|
||||||
|
|
||||||
|
r.min_prng = dmin;
|
||||||
|
r.max_prng = dmax;
|
||||||
|
r.mid_prng = davg;
|
||||||
|
|
||||||
|
free(crypto);
|
||||||
|
|
||||||
|
nfc_deactivate();
|
||||||
|
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct nonce_info nested_attack(
|
||||||
|
FuriHalNfcTxRxContext* tx_rx,
|
||||||
|
uint8_t blockNo,
|
||||||
|
uint8_t keyType,
|
||||||
|
uint8_t targetBlockNo,
|
||||||
|
uint8_t targetKeyType,
|
||||||
|
uint64_t ui64Key,
|
||||||
|
uint32_t distance,
|
||||||
|
uint32_t delay) {
|
||||||
|
uint32_t cuid = 0;
|
||||||
|
Crypto1* crypto = malloc(sizeof(Crypto1));
|
||||||
|
uint8_t par_array[4] = {0x00};
|
||||||
|
uint32_t nt1, nt2, ks1, i = 0, j = 0;
|
||||||
|
struct nonce_info r;
|
||||||
|
uint32_t dmin = distance - 2;
|
||||||
|
uint32_t dmax = distance + 2;
|
||||||
|
|
||||||
|
r.full = false;
|
||||||
|
|
||||||
|
for(i = 0; i < 2; i++) { // look for exactly two different nonces
|
||||||
|
r.target_nt[i] = 0;
|
||||||
|
|
||||||
|
while(r.target_nt[i] == 0) { // continue until we have an unambiguous nonce
|
||||||
|
nfc_activate();
|
||||||
|
if(!furi_hal_nfc_activate_nfca(200, &cuid)) {
|
||||||
|
free(crypto);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
r.cuid = cuid;
|
||||||
|
|
||||||
|
mifare_classic_authex(crypto, tx_rx, cuid, blockNo, keyType, ui64Key, false, &nt1);
|
||||||
|
|
||||||
|
furi_delay_us(delay);
|
||||||
|
|
||||||
|
bool success = mifare_sendcmd_short(
|
||||||
|
crypto, tx_rx, true, 0x60 + (targetKeyType & 0x01), targetBlockNo);
|
||||||
|
|
||||||
|
if(!success) continue;
|
||||||
|
|
||||||
|
nt2 = nfc_util_bytes2num(tx_rx->rx_data, 4);
|
||||||
|
|
||||||
|
// Parity validity check
|
||||||
|
for(j = 0; j < 4; j++) {
|
||||||
|
par_array[j] =
|
||||||
|
(oddparity8(tx_rx->rx_data[j]) != ((tx_rx->rx_parity[0] >> (7 - j)) & 0x01));
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t ncount = 0;
|
||||||
|
uint32_t nttest = prng_successor(nt1, dmin - 1);
|
||||||
|
|
||||||
|
for(j = dmin; j < dmax + 1; j++) {
|
||||||
|
nttest = prng_successor(nttest, 1);
|
||||||
|
ks1 = nt2 ^ nttest;
|
||||||
|
|
||||||
|
if(valid_nonce(nttest, nt2, ks1, par_array)) {
|
||||||
|
if(ncount > 0) { // we are only interested in disambiguous nonces, try again
|
||||||
|
FURI_LOG_D(TAG, "Nonce#%lu: dismissed (ambiguous), ntdist=%lu", i + 1, j);
|
||||||
|
r.target_nt[i] = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(delay) {
|
||||||
|
// will predict later
|
||||||
|
r.target_nt[i] = nt1;
|
||||||
|
r.target_ks[i] = nt2;
|
||||||
|
} else {
|
||||||
|
r.target_nt[i] = nttest;
|
||||||
|
r.target_ks[i] = ks1;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(&r.parity[i], par_array, 4);
|
||||||
|
ncount++;
|
||||||
|
|
||||||
|
if(i == 1 &&
|
||||||
|
(r.target_nt[0] == r.target_nt[1] ||
|
||||||
|
r.target_ks[0] == r.target_ks[1])) { // we need two different nonces
|
||||||
|
r.target_nt[i] = 0;
|
||||||
|
FURI_LOG_D(TAG, "Nonce#2: dismissed (= nonce#1), ntdist=%lu", j);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
FURI_LOG_D(TAG, "Nonce#%lu: valid, ntdist=%lu", i + 1, j);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(r.target_nt[i] == 0 && j == dmax + 1) {
|
||||||
|
FURI_LOG_D(TAG, "Nonce#%lu: dismissed (all invalid)", i + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(r.target_nt[0] && r.target_nt[1]) {
|
||||||
|
r.full = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(crypto);
|
||||||
|
|
||||||
|
nfc_deactivate();
|
||||||
|
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct nonce_info_hard nested_hard_nonce_attack(
|
||||||
|
FuriHalNfcTxRxContext* tx_rx,
|
||||||
|
uint8_t blockNo,
|
||||||
|
uint8_t keyType,
|
||||||
|
uint8_t targetBlockNo,
|
||||||
|
uint8_t targetKeyType,
|
||||||
|
uint64_t ui64Key,
|
||||||
|
uint32_t* found,
|
||||||
|
uint32_t* first_byte_sum,
|
||||||
|
Stream* file_stream) {
|
||||||
|
uint32_t cuid = 0;
|
||||||
|
uint8_t same = 0;
|
||||||
|
uint64_t previous = 0;
|
||||||
|
Crypto1* crypto = malloc(sizeof(Crypto1));
|
||||||
|
uint8_t par_array[4] = {0x00};
|
||||||
|
struct nonce_info_hard r;
|
||||||
|
r.full = false;
|
||||||
|
r.static_encrypted = false;
|
||||||
|
|
||||||
|
for(uint32_t i = 0; i < 8; i++) {
|
||||||
|
nfc_activate();
|
||||||
|
if(!furi_hal_nfc_activate_nfca(200, &cuid)) {
|
||||||
|
free(crypto);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
r.cuid = cuid;
|
||||||
|
|
||||||
|
if(!mifare_classic_authex(crypto, tx_rx, cuid, blockNo, keyType, ui64Key, false, NULL))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if(!mifare_sendcmd_short(crypto, tx_rx, true, 0x60 + (targetKeyType & 0x01), targetBlockNo))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
uint64_t nt = nfc_util_bytes2num(tx_rx->rx_data, 4);
|
||||||
|
|
||||||
|
for(uint32_t j = 0; j < 4; j++) {
|
||||||
|
par_array[j] =
|
||||||
|
(oddparity8(tx_rx->rx_data[j]) != ((tx_rx->rx_parity[0] >> (7 - j)) & 0x01));
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t pbits = 0;
|
||||||
|
for(uint8_t j = 0; j < 4; j++) {
|
||||||
|
uint8_t p = oddparity8(tx_rx->rx_data[j]);
|
||||||
|
if(par_array[j]) {
|
||||||
|
p ^= 1;
|
||||||
|
}
|
||||||
|
pbits <<= 1;
|
||||||
|
pbits |= p;
|
||||||
|
}
|
||||||
|
|
||||||
|
// update unique nonces
|
||||||
|
if(!found[tx_rx->rx_data[0]]) {
|
||||||
|
*first_byte_sum += evenparity32(pbits & 0x08);
|
||||||
|
found[tx_rx->rx_data[0]]++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(nt == previous) {
|
||||||
|
same++;
|
||||||
|
}
|
||||||
|
|
||||||
|
previous = nt;
|
||||||
|
|
||||||
|
FuriString* row = furi_string_alloc_printf("%llu|%u\n", nt, pbits);
|
||||||
|
stream_write_string(file_stream, row);
|
||||||
|
|
||||||
|
FURI_LOG_D(TAG, "Accured %lu/8 nonces", i + 1);
|
||||||
|
furi_string_free(row);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(same > 4) {
|
||||||
|
r.static_encrypted = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
r.full = true;
|
||||||
|
|
||||||
|
free(crypto);
|
||||||
|
|
||||||
|
nfc_deactivate();
|
||||||
|
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
NestedCheckKeyResult nested_check_key(
|
||||||
|
FuriHalNfcTxRxContext* tx_rx,
|
||||||
|
uint8_t blockNo,
|
||||||
|
uint8_t keyType,
|
||||||
|
uint64_t ui64Key) {
|
||||||
|
uint32_t cuid = 0;
|
||||||
|
uint32_t nt;
|
||||||
|
|
||||||
|
nfc_activate();
|
||||||
|
if(!furi_hal_nfc_activate_nfca(200, &cuid)) return NestedCheckKeyNoTag;
|
||||||
|
|
||||||
|
FURI_LOG_D(
|
||||||
|
TAG, "Checking %c key %012llX for block %u", !keyType ? 'A' : 'B', ui64Key, blockNo);
|
||||||
|
|
||||||
|
Crypto1* crypto = malloc(sizeof(Crypto1));
|
||||||
|
|
||||||
|
bool success =
|
||||||
|
mifare_classic_authex(crypto, tx_rx, cuid, blockNo, keyType, ui64Key, false, &nt);
|
||||||
|
|
||||||
|
free(crypto);
|
||||||
|
|
||||||
|
nfc_deactivate();
|
||||||
|
|
||||||
|
return success ? NestedCheckKeyValid : NestedCheckKeyInvalid;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool nested_check_block(FuriHalNfcTxRxContext* tx_rx, uint8_t blockNo, uint8_t keyType) {
|
||||||
|
uint32_t cuid = 0;
|
||||||
|
|
||||||
|
nfc_activate();
|
||||||
|
if(!furi_hal_nfc_activate_nfca(200, &cuid)) return false;
|
||||||
|
|
||||||
|
Crypto1* crypto = malloc(sizeof(Crypto1));
|
||||||
|
|
||||||
|
bool success = mifare_sendcmd_short(crypto, tx_rx, false, 0x60 + (keyType & 0x01), blockNo);
|
||||||
|
|
||||||
|
free(crypto);
|
||||||
|
|
||||||
|
nfc_deactivate();
|
||||||
|
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
void nested_get_data(FuriHalNfcDevData* dev_data) {
|
||||||
|
nfc_activate();
|
||||||
|
furi_hal_nfc_detect(dev_data, 400);
|
||||||
|
nfc_deactivate();
|
||||||
|
}
|
||||||
|
|
||||||
|
void nfc_activate() {
|
||||||
|
nfc_deactivate();
|
||||||
|
|
||||||
|
// Setup nfc poller
|
||||||
|
furi_hal_nfc_exit_sleep();
|
||||||
|
furi_hal_nfc_ll_txrx_on();
|
||||||
|
furi_hal_nfc_ll_poll();
|
||||||
|
if(furi_hal_nfc_ll_set_mode(
|
||||||
|
FuriHalNfcModePollNfca, FuriHalNfcBitrate106, FuriHalNfcBitrate106) !=
|
||||||
|
FuriHalNfcReturnOk)
|
||||||
|
return;
|
||||||
|
|
||||||
|
furi_hal_nfc_ll_set_fdt_listen(FURI_HAL_NFC_LL_FDT_LISTEN_NFCA_POLLER);
|
||||||
|
furi_hal_nfc_ll_set_fdt_poll(FURI_HAL_NFC_LL_FDT_POLL_NFCA_POLLER);
|
||||||
|
furi_hal_nfc_ll_set_error_handling(FuriHalNfcErrorHandlingNfc);
|
||||||
|
furi_hal_nfc_ll_set_guard_time(FURI_HAL_NFC_LL_GT_NFCA);
|
||||||
|
}
|
||||||
|
|
||||||
|
void nfc_deactivate() {
|
||||||
|
furi_hal_nfc_ll_txrx_off();
|
||||||
|
furi_hal_nfc_start_sleep();
|
||||||
|
furi_hal_nfc_sleep();
|
||||||
|
}
|
||||||
118
applications/external/mifare_nested/lib/nested/nested.h
vendored
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <lib/nfc/protocols/nfc_util.h>
|
||||||
|
#include <lib/nfc/protocols/mifare_classic.h>
|
||||||
|
#include <lib/nfc/protocols/crypto1.h>
|
||||||
|
|
||||||
|
#include <storage/storage.h>
|
||||||
|
#include <stream/stream.h>
|
||||||
|
#include <stream/buffered_file_stream.h>
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
MifareNestedNonceNoTag,
|
||||||
|
MifareNestedNonceWeak,
|
||||||
|
MifareNestedNonceStatic,
|
||||||
|
MifareNestedNonceHard,
|
||||||
|
} MifareNestedNonceType;
|
||||||
|
|
||||||
|
MifareNestedNonceType nested_check_nonce_type(FuriHalNfcTxRxContext* tx_rx, uint8_t blockNo);
|
||||||
|
|
||||||
|
struct nonce_info_static {
|
||||||
|
uint32_t cuid;
|
||||||
|
uint32_t target_nt[2];
|
||||||
|
uint32_t target_ks[2];
|
||||||
|
bool full;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct nonce_info_hard {
|
||||||
|
uint32_t cuid;
|
||||||
|
bool static_encrypted;
|
||||||
|
bool full;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct nonce_info {
|
||||||
|
uint32_t cuid;
|
||||||
|
uint32_t target_nt[2];
|
||||||
|
uint32_t target_ks[2];
|
||||||
|
uint8_t parity[2][4];
|
||||||
|
bool full;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct distance_info {
|
||||||
|
uint32_t min_prng;
|
||||||
|
uint32_t max_prng;
|
||||||
|
uint32_t mid_prng;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct nonce_info_static nested_static_nonce_attack(
|
||||||
|
FuriHalNfcTxRxContext* tx_rx,
|
||||||
|
uint8_t blockNo,
|
||||||
|
uint8_t keyType,
|
||||||
|
uint8_t targetBlockNo,
|
||||||
|
uint8_t targetKeyType,
|
||||||
|
uint64_t ui64Key);
|
||||||
|
|
||||||
|
struct nonce_info nested_attack(
|
||||||
|
FuriHalNfcTxRxContext* tx_rx,
|
||||||
|
uint8_t blockNo,
|
||||||
|
uint8_t keyType,
|
||||||
|
uint8_t targetBlockNo,
|
||||||
|
uint8_t targetKeyType,
|
||||||
|
uint64_t ui64Key,
|
||||||
|
uint32_t distance,
|
||||||
|
uint32_t delay);
|
||||||
|
|
||||||
|
struct nonce_info_hard nested_hard_nonce_attack(
|
||||||
|
FuriHalNfcTxRxContext* tx_rx,
|
||||||
|
uint8_t blockNo,
|
||||||
|
uint8_t keyType,
|
||||||
|
uint8_t targetBlockNo,
|
||||||
|
uint8_t targetKeyType,
|
||||||
|
uint64_t ui64Key,
|
||||||
|
uint32_t* found,
|
||||||
|
uint32_t* first_byte_sum,
|
||||||
|
Stream* file_stream);
|
||||||
|
|
||||||
|
uint32_t nested_calibrate_distance(
|
||||||
|
FuriHalNfcTxRxContext* tx_rx,
|
||||||
|
uint8_t blockNo,
|
||||||
|
uint8_t keyType,
|
||||||
|
uint64_t ui64Key,
|
||||||
|
uint32_t delay,
|
||||||
|
bool full);
|
||||||
|
|
||||||
|
struct distance_info nested_calibrate_distance_info(
|
||||||
|
FuriHalNfcTxRxContext* tx_rx,
|
||||||
|
uint8_t blockNo,
|
||||||
|
uint8_t keyType,
|
||||||
|
uint64_t ui64Key);
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
NestedCheckKeyNoTag,
|
||||||
|
NestedCheckKeyValid,
|
||||||
|
NestedCheckKeyInvalid,
|
||||||
|
} NestedCheckKeyResult;
|
||||||
|
|
||||||
|
NestedCheckKeyResult nested_check_key(
|
||||||
|
FuriHalNfcTxRxContext* tx_rx,
|
||||||
|
uint8_t blockNo,
|
||||||
|
uint8_t keyType,
|
||||||
|
uint64_t ui64Key);
|
||||||
|
|
||||||
|
bool nested_check_block(FuriHalNfcTxRxContext* tx_rx, uint8_t blockNo, uint8_t keyType);
|
||||||
|
|
||||||
|
void nested_get_data();
|
||||||
|
|
||||||
|
bool mifare_classic_authex(
|
||||||
|
Crypto1* crypto,
|
||||||
|
FuriHalNfcTxRxContext* tx_rx,
|
||||||
|
uint32_t uid,
|
||||||
|
uint32_t blockNo,
|
||||||
|
uint32_t keyType,
|
||||||
|
uint64_t ui64Key,
|
||||||
|
bool isNested,
|
||||||
|
uint32_t* ntptr);
|
||||||
|
|
||||||
|
void nfc_activate();
|
||||||
|
|
||||||
|
void nfc_deactivate();
|
||||||
71
applications/external/mifare_nested/lib/parity/parity.c
vendored
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
#include "parity.h"
|
||||||
|
|
||||||
|
uint32_t __paritysi2(uint32_t a) {
|
||||||
|
uint32_t x = (uint32_t)a;
|
||||||
|
x ^= x >> 16;
|
||||||
|
x ^= x >> 8;
|
||||||
|
x ^= x >> 4;
|
||||||
|
return (0x6996 >> (x & 0xF)) & 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const uint8_t g_odd_byte_parity[256] = {
|
||||||
|
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0,
|
||||||
|
1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1,
|
||||||
|
1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1,
|
||||||
|
0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0,
|
||||||
|
1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1,
|
||||||
|
0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0,
|
||||||
|
0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1,
|
||||||
|
0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
|
||||||
|
1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1};
|
||||||
|
|
||||||
|
#define ODD_PARITY8(x) \
|
||||||
|
{ g_odd_byte_parity[x] }
|
||||||
|
#define EVEN_PARITY8(x) \
|
||||||
|
{ !g_odd_byte_parity[x] }
|
||||||
|
|
||||||
|
uint8_t oddparity8(const uint8_t x) {
|
||||||
|
return g_odd_byte_parity[x];
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t evenparity8(const uint8_t x) {
|
||||||
|
return !g_odd_byte_parity[x];
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t evenparity16(uint16_t x) {
|
||||||
|
#if !defined __GNUC__
|
||||||
|
x ^= x >> 8;
|
||||||
|
return EVEN_PARITY8(x);
|
||||||
|
#else
|
||||||
|
return (__builtin_parity(x) & 0xFF);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t oddparity16(uint16_t x) {
|
||||||
|
#if !defined __GNUC__
|
||||||
|
x ^= x >> 8;
|
||||||
|
return ODD_PARITY8(x);
|
||||||
|
#else
|
||||||
|
return !__builtin_parity(x);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t evenparity32(uint32_t x) {
|
||||||
|
#if !defined __GNUC__
|
||||||
|
x ^= x >> 16;
|
||||||
|
x ^= x >> 8;
|
||||||
|
return EVEN_PARITY8(x);
|
||||||
|
#else
|
||||||
|
return (__builtin_parity(x) & 0xFF);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t oddparity32(uint32_t x) {
|
||||||
|
#if !defined __GNUC__
|
||||||
|
x ^= x >> 16;
|
||||||
|
x ^= x >> 8;
|
||||||
|
return ODD_PARITY8(x);
|
||||||
|
#else
|
||||||
|
return !__builtin_parity(x);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
10
applications/external/mifare_nested/lib/parity/parity.h
vendored
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
#include "stdint.h"
|
||||||
|
|
||||||
|
uint8_t oddparity8(const uint8_t x);
|
||||||
|
uint8_t evenparity8(const uint8_t x);
|
||||||
|
|
||||||
|
uint8_t evenparity16(uint16_t x);
|
||||||
|
uint8_t oddparity16(uint16_t x);
|
||||||
|
|
||||||
|
uint8_t evenparity32(uint32_t x);
|
||||||
|
uint8_t oddparity32(uint32_t x);
|
||||||
408
applications/external/mifare_nested/mifare_nested.c
vendored
Normal file
@@ -0,0 +1,408 @@
|
|||||||
|
#include "mifare_nested_i.h"
|
||||||
|
#include <gui/elements.h>
|
||||||
|
|
||||||
|
bool mifare_nested_custom_event_callback(void* context, uint32_t event) {
|
||||||
|
furi_assert(context);
|
||||||
|
MifareNested* mifare_nested = context;
|
||||||
|
return scene_manager_handle_custom_event(mifare_nested->scene_manager, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool mifare_nested_back_event_callback(void* context) {
|
||||||
|
furi_assert(context);
|
||||||
|
MifareNested* mifare_nested = context;
|
||||||
|
return scene_manager_handle_back_event(mifare_nested->scene_manager);
|
||||||
|
}
|
||||||
|
|
||||||
|
void mifare_nested_tick_event_callback(void* context) {
|
||||||
|
furi_assert(context);
|
||||||
|
MifareNested* mifare_nested = context;
|
||||||
|
scene_manager_handle_tick_event(mifare_nested->scene_manager);
|
||||||
|
}
|
||||||
|
|
||||||
|
void mifare_nested_show_loading_popup(void* context, bool show) {
|
||||||
|
MifareNested* mifare_nested = context;
|
||||||
|
TaskHandle_t timer_task = xTaskGetHandle(configTIMER_SERVICE_TASK_NAME);
|
||||||
|
|
||||||
|
if(show) {
|
||||||
|
// Raise timer priority so that animations can play
|
||||||
|
vTaskPrioritySet(timer_task, configMAX_PRIORITIES - 1);
|
||||||
|
view_dispatcher_switch_to_view(mifare_nested->view_dispatcher, MifareNestedViewLoading);
|
||||||
|
} else {
|
||||||
|
// Restore default timer priority
|
||||||
|
vTaskPrioritySet(timer_task, configTIMER_TASK_PRIORITY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
NestedState* collection_alloc() {
|
||||||
|
NestedState* nested = malloc(sizeof(NestedState));
|
||||||
|
nested->view = view_alloc();
|
||||||
|
view_allocate_model(nested->view, ViewModelTypeLocking, sizeof(NestedAttackViewModel));
|
||||||
|
with_view_model(
|
||||||
|
nested->view,
|
||||||
|
NestedAttackViewModel * model,
|
||||||
|
{
|
||||||
|
model->header = furi_string_alloc();
|
||||||
|
furi_string_set(model->header, "Collecting nonces");
|
||||||
|
model->keys_count = 0;
|
||||||
|
model->hardnested_states = 0;
|
||||||
|
model->lost_tag = false;
|
||||||
|
model->calibrating = false;
|
||||||
|
model->need_prediction = false;
|
||||||
|
model->hardnested = false;
|
||||||
|
},
|
||||||
|
false);
|
||||||
|
|
||||||
|
return nested;
|
||||||
|
}
|
||||||
|
|
||||||
|
CheckKeysState* check_keys_alloc() {
|
||||||
|
CheckKeysState* state = malloc(sizeof(CheckKeysState));
|
||||||
|
state->view = view_alloc();
|
||||||
|
view_allocate_model(state->view, ViewModelTypeLocking, sizeof(CheckKeysViewModel));
|
||||||
|
with_view_model(
|
||||||
|
state->view,
|
||||||
|
CheckKeysViewModel * model,
|
||||||
|
{
|
||||||
|
model->header = furi_string_alloc();
|
||||||
|
furi_string_set(model->header, "Checking keys");
|
||||||
|
model->lost_tag = false;
|
||||||
|
},
|
||||||
|
false);
|
||||||
|
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void nested_draw_callback(Canvas* canvas, void* model) {
|
||||||
|
NestedAttackViewModel* m = model;
|
||||||
|
|
||||||
|
if(m->lost_tag) {
|
||||||
|
canvas_set_font(canvas, FontPrimary);
|
||||||
|
canvas_draw_str_aligned(canvas, 64, 4, AlignCenter, AlignTop, "Lost the tag!");
|
||||||
|
canvas_set_font(canvas, FontSecondary);
|
||||||
|
elements_multiline_text_aligned(
|
||||||
|
canvas, 64, 23, AlignCenter, AlignTop, "Make sure the tag is\npositioned correctly.");
|
||||||
|
} else if(m->calibrating) {
|
||||||
|
canvas_set_font(canvas, FontPrimary);
|
||||||
|
canvas_draw_str_aligned(canvas, 64, 4, AlignCenter, AlignTop, "Calibrating...");
|
||||||
|
canvas_set_font(canvas, FontSecondary);
|
||||||
|
if(!m->need_prediction) {
|
||||||
|
elements_multiline_text_aligned(
|
||||||
|
canvas, 64, 23, AlignCenter, AlignTop, "Don't touch or move\nFlipper/Tag!");
|
||||||
|
} else {
|
||||||
|
elements_multiline_text_aligned(
|
||||||
|
canvas, 64, 18, AlignCenter, AlignTop, "Don't touch or move tag!");
|
||||||
|
canvas_set_font(canvas, FontPrimary);
|
||||||
|
elements_multiline_text_aligned(
|
||||||
|
canvas, 64, 30, AlignCenter, AlignTop, "Calibration will take\nmore time");
|
||||||
|
}
|
||||||
|
} else if(m->hardnested) {
|
||||||
|
char draw_str[32] = {};
|
||||||
|
canvas_set_font(canvas, FontPrimary);
|
||||||
|
canvas_draw_str_aligned(
|
||||||
|
canvas, 64, 2, AlignCenter, AlignTop, furi_string_get_cstr(m->header));
|
||||||
|
canvas_set_font(canvas, FontSecondary);
|
||||||
|
|
||||||
|
float progress =
|
||||||
|
m->keys_count == 0 ? 0 : (float)(m->nonces_collected) / (float)(m->keys_count);
|
||||||
|
|
||||||
|
if(progress > 1.0) {
|
||||||
|
progress = 1.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
elements_progress_bar(canvas, 5, 15, 120, progress);
|
||||||
|
canvas_set_font(canvas, FontSecondary);
|
||||||
|
snprintf(
|
||||||
|
draw_str,
|
||||||
|
sizeof(draw_str),
|
||||||
|
"Nonces collected: %lu/%lu",
|
||||||
|
m->nonces_collected,
|
||||||
|
m->keys_count);
|
||||||
|
canvas_draw_str_aligned(canvas, 1, 28, AlignLeft, AlignTop, draw_str);
|
||||||
|
snprintf(draw_str, sizeof(draw_str), "States found: %lu/256", m->hardnested_states);
|
||||||
|
canvas_draw_str_aligned(canvas, 1, 40, AlignLeft, AlignTop, draw_str);
|
||||||
|
} else {
|
||||||
|
char draw_str[32] = {};
|
||||||
|
canvas_set_font(canvas, FontPrimary);
|
||||||
|
canvas_draw_str_aligned(
|
||||||
|
canvas, 64, 2, AlignCenter, AlignTop, furi_string_get_cstr(m->header));
|
||||||
|
canvas_set_font(canvas, FontSecondary);
|
||||||
|
|
||||||
|
float progress =
|
||||||
|
m->keys_count == 0 ? 0 : (float)(m->nonces_collected) / (float)(m->keys_count);
|
||||||
|
|
||||||
|
if(progress > 1.0) {
|
||||||
|
progress = 1.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
elements_progress_bar(canvas, 5, 15, 120, progress);
|
||||||
|
canvas_set_font(canvas, FontSecondary);
|
||||||
|
snprintf(
|
||||||
|
draw_str,
|
||||||
|
sizeof(draw_str),
|
||||||
|
"Nonces collected: %lu/%lu",
|
||||||
|
m->nonces_collected,
|
||||||
|
m->keys_count);
|
||||||
|
canvas_draw_str_aligned(canvas, 1, 28, AlignLeft, AlignTop, draw_str);
|
||||||
|
}
|
||||||
|
|
||||||
|
elements_button_center(canvas, "Stop");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void check_keys_draw_callback(Canvas* canvas, void* model) {
|
||||||
|
CheckKeysViewModel* m = model;
|
||||||
|
|
||||||
|
if(m->lost_tag) {
|
||||||
|
canvas_set_font(canvas, FontPrimary);
|
||||||
|
canvas_draw_str_aligned(canvas, 64, 4, AlignCenter, AlignTop, "Lost the tag!");
|
||||||
|
canvas_set_font(canvas, FontSecondary);
|
||||||
|
elements_multiline_text_aligned(
|
||||||
|
canvas, 64, 23, AlignCenter, AlignTop, "Make sure the tag is\npositioned correctly.");
|
||||||
|
} else if(m->processing_keys) {
|
||||||
|
canvas_set_font(canvas, FontPrimary);
|
||||||
|
canvas_draw_str_aligned(canvas, 64, 4, AlignCenter, AlignTop, "Processing keys...");
|
||||||
|
canvas_set_font(canvas, FontSecondary);
|
||||||
|
elements_multiline_text_aligned(
|
||||||
|
canvas, 64, 23, AlignCenter, AlignTop, "Checking which keys you\nalready have...");
|
||||||
|
} else {
|
||||||
|
char draw_str[32] = {};
|
||||||
|
char draw_sub_str[32] = {};
|
||||||
|
canvas_set_font(canvas, FontPrimary);
|
||||||
|
canvas_draw_str_aligned(
|
||||||
|
canvas, 64, 2, AlignCenter, AlignTop, furi_string_get_cstr(m->header));
|
||||||
|
canvas_set_font(canvas, FontSecondary);
|
||||||
|
|
||||||
|
float progress = m->keys_count == 0 ? 0 :
|
||||||
|
(float)(m->keys_checked) / (float)(m->keys_count);
|
||||||
|
|
||||||
|
if(progress > 1.0) {
|
||||||
|
progress = 1.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
elements_progress_bar(canvas, 5, 15, 120, progress);
|
||||||
|
canvas_set_font(canvas, FontSecondary);
|
||||||
|
snprintf(
|
||||||
|
draw_str, sizeof(draw_str), "Keys checked: %lu/%lu", m->keys_checked, m->keys_count);
|
||||||
|
canvas_draw_str_aligned(canvas, 1, 28, AlignLeft, AlignTop, draw_str);
|
||||||
|
snprintf(
|
||||||
|
draw_sub_str,
|
||||||
|
sizeof(draw_sub_str),
|
||||||
|
"Keys found: %lu/%lu",
|
||||||
|
m->keys_found,
|
||||||
|
m->keys_total);
|
||||||
|
canvas_draw_str_aligned(canvas, 1, 40, AlignLeft, AlignTop, draw_sub_str);
|
||||||
|
}
|
||||||
|
|
||||||
|
elements_button_center(canvas, "Stop");
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool nested_input_callback(InputEvent* event, void* context) {
|
||||||
|
MifareNested* mifare_nested = context;
|
||||||
|
|
||||||
|
bool consumed = false;
|
||||||
|
|
||||||
|
if(event->type == InputTypeShort && (event->key == InputKeyBack || event->key == InputKeyOk)) {
|
||||||
|
scene_manager_search_and_switch_to_previous_scene(mifare_nested->scene_manager, 0);
|
||||||
|
consumed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return consumed;
|
||||||
|
}
|
||||||
|
|
||||||
|
MifareNested* mifare_nested_alloc() {
|
||||||
|
MifareNested* mifare_nested = malloc(sizeof(MifareNested));
|
||||||
|
|
||||||
|
mifare_nested->worker = mifare_nested_worker_alloc();
|
||||||
|
mifare_nested->view_dispatcher = view_dispatcher_alloc();
|
||||||
|
mifare_nested->scene_manager =
|
||||||
|
scene_manager_alloc(&mifare_nested_scene_handlers, mifare_nested);
|
||||||
|
view_dispatcher_enable_queue(mifare_nested->view_dispatcher);
|
||||||
|
view_dispatcher_set_event_callback_context(mifare_nested->view_dispatcher, mifare_nested);
|
||||||
|
view_dispatcher_set_custom_event_callback(
|
||||||
|
mifare_nested->view_dispatcher, mifare_nested_custom_event_callback);
|
||||||
|
view_dispatcher_set_navigation_event_callback(
|
||||||
|
mifare_nested->view_dispatcher, mifare_nested_back_event_callback);
|
||||||
|
view_dispatcher_set_tick_event_callback(
|
||||||
|
mifare_nested->view_dispatcher, mifare_nested_tick_event_callback, 100);
|
||||||
|
|
||||||
|
// Nfc device
|
||||||
|
mifare_nested->nfc_dev = nfc_device_alloc();
|
||||||
|
|
||||||
|
// Open GUI record
|
||||||
|
mifare_nested->gui = furi_record_open(RECORD_GUI);
|
||||||
|
view_dispatcher_attach_to_gui(
|
||||||
|
mifare_nested->view_dispatcher, mifare_nested->gui, ViewDispatcherTypeFullscreen);
|
||||||
|
|
||||||
|
// Open Notification record
|
||||||
|
mifare_nested->notifications = furi_record_open(RECORD_NOTIFICATION);
|
||||||
|
|
||||||
|
// Submenu
|
||||||
|
mifare_nested->submenu = submenu_alloc();
|
||||||
|
view_dispatcher_add_view(
|
||||||
|
mifare_nested->view_dispatcher,
|
||||||
|
MifareNestedViewMenu,
|
||||||
|
submenu_get_view(mifare_nested->submenu));
|
||||||
|
|
||||||
|
// Popup
|
||||||
|
mifare_nested->popup = popup_alloc();
|
||||||
|
view_dispatcher_add_view(
|
||||||
|
mifare_nested->view_dispatcher,
|
||||||
|
MifareNestedViewPopup,
|
||||||
|
popup_get_view(mifare_nested->popup));
|
||||||
|
|
||||||
|
// Loading
|
||||||
|
mifare_nested->loading = loading_alloc();
|
||||||
|
view_dispatcher_add_view(
|
||||||
|
mifare_nested->view_dispatcher,
|
||||||
|
MifareNestedViewLoading,
|
||||||
|
loading_get_view(mifare_nested->loading));
|
||||||
|
|
||||||
|
// Text Input
|
||||||
|
mifare_nested->text_input = text_input_alloc();
|
||||||
|
view_dispatcher_add_view(
|
||||||
|
mifare_nested->view_dispatcher,
|
||||||
|
MifareNestedViewTextInput,
|
||||||
|
text_input_get_view(mifare_nested->text_input));
|
||||||
|
|
||||||
|
// Custom Widget
|
||||||
|
mifare_nested->widget = widget_alloc();
|
||||||
|
view_dispatcher_add_view(
|
||||||
|
mifare_nested->view_dispatcher,
|
||||||
|
MifareNestedViewWidget,
|
||||||
|
widget_get_view(mifare_nested->widget));
|
||||||
|
|
||||||
|
// Variable Item List
|
||||||
|
mifare_nested->variable_item_list = variable_item_list_alloc();
|
||||||
|
view_dispatcher_add_view(
|
||||||
|
mifare_nested->view_dispatcher,
|
||||||
|
MifareNestedViewVariableList,
|
||||||
|
variable_item_list_get_view(mifare_nested->variable_item_list));
|
||||||
|
|
||||||
|
// Nested attack state
|
||||||
|
NestedState* plugin_state = collection_alloc();
|
||||||
|
view_set_context(plugin_state->view, mifare_nested);
|
||||||
|
mifare_nested->nested_state = plugin_state;
|
||||||
|
view_dispatcher_add_view(
|
||||||
|
mifare_nested->view_dispatcher, MifareNestedViewCollecting, plugin_state->view);
|
||||||
|
|
||||||
|
// Check keys attack state
|
||||||
|
CheckKeysState* keys_state = check_keys_alloc();
|
||||||
|
view_set_context(keys_state->view, mifare_nested);
|
||||||
|
mifare_nested->keys_state = keys_state;
|
||||||
|
view_dispatcher_add_view(
|
||||||
|
mifare_nested->view_dispatcher, MifareNestedViewCheckKeys, keys_state->view);
|
||||||
|
|
||||||
|
KeyInfo_t* key_info = malloc(sizeof(KeyInfo_t));
|
||||||
|
mifare_nested->keys = key_info;
|
||||||
|
|
||||||
|
MifareNestedSettings* settings = malloc(sizeof(MifareNestedSettings));
|
||||||
|
settings->only_hardnested = false;
|
||||||
|
mifare_nested->settings = settings;
|
||||||
|
|
||||||
|
view_set_draw_callback(plugin_state->view, nested_draw_callback);
|
||||||
|
view_set_input_callback(plugin_state->view, nested_input_callback);
|
||||||
|
|
||||||
|
view_set_draw_callback(keys_state->view, check_keys_draw_callback);
|
||||||
|
view_set_input_callback(keys_state->view, nested_input_callback);
|
||||||
|
|
||||||
|
mifare_nested->collecting_type = MifareNestedWorkerStateReady;
|
||||||
|
mifare_nested->run = NestedRunIdle;
|
||||||
|
|
||||||
|
return mifare_nested;
|
||||||
|
}
|
||||||
|
|
||||||
|
void mifare_nested_free(MifareNested* mifare_nested) {
|
||||||
|
furi_assert(mifare_nested);
|
||||||
|
|
||||||
|
// Nfc device
|
||||||
|
nfc_device_free(mifare_nested->nfc_dev);
|
||||||
|
|
||||||
|
// Submenu
|
||||||
|
view_dispatcher_remove_view(mifare_nested->view_dispatcher, MifareNestedViewMenu);
|
||||||
|
submenu_free(mifare_nested->submenu);
|
||||||
|
|
||||||
|
// Popup
|
||||||
|
view_dispatcher_remove_view(mifare_nested->view_dispatcher, MifareNestedViewPopup);
|
||||||
|
popup_free(mifare_nested->popup);
|
||||||
|
|
||||||
|
// Loading
|
||||||
|
view_dispatcher_remove_view(mifare_nested->view_dispatcher, MifareNestedViewLoading);
|
||||||
|
loading_free(mifare_nested->loading);
|
||||||
|
|
||||||
|
// TextInput
|
||||||
|
view_dispatcher_remove_view(mifare_nested->view_dispatcher, MifareNestedViewTextInput);
|
||||||
|
text_input_free(mifare_nested->text_input);
|
||||||
|
|
||||||
|
// Custom Widget
|
||||||
|
view_dispatcher_remove_view(mifare_nested->view_dispatcher, MifareNestedViewWidget);
|
||||||
|
widget_free(mifare_nested->widget);
|
||||||
|
|
||||||
|
// Variable Item List
|
||||||
|
view_dispatcher_remove_view(mifare_nested->view_dispatcher, MifareNestedViewVariableList);
|
||||||
|
variable_item_list_free(mifare_nested->variable_item_list);
|
||||||
|
|
||||||
|
// Nested
|
||||||
|
view_dispatcher_remove_view(mifare_nested->view_dispatcher, MifareNestedViewCollecting);
|
||||||
|
|
||||||
|
// Check keys
|
||||||
|
view_dispatcher_remove_view(mifare_nested->view_dispatcher, MifareNestedViewCheckKeys);
|
||||||
|
|
||||||
|
// Nonces states
|
||||||
|
free(mifare_nested->nonces);
|
||||||
|
free(mifare_nested->nested_state);
|
||||||
|
|
||||||
|
// Keys
|
||||||
|
free(mifare_nested->keys);
|
||||||
|
|
||||||
|
// Settings
|
||||||
|
free(mifare_nested->settings);
|
||||||
|
|
||||||
|
// Worker
|
||||||
|
mifare_nested_worker_stop(mifare_nested->worker);
|
||||||
|
mifare_nested_worker_free(mifare_nested->worker);
|
||||||
|
|
||||||
|
// View Dispatcher
|
||||||
|
view_dispatcher_free(mifare_nested->view_dispatcher);
|
||||||
|
|
||||||
|
// Scene Manager
|
||||||
|
scene_manager_free(mifare_nested->scene_manager);
|
||||||
|
|
||||||
|
// GUI
|
||||||
|
furi_record_close(RECORD_GUI);
|
||||||
|
mifare_nested->gui = NULL;
|
||||||
|
|
||||||
|
// Notifications
|
||||||
|
furi_record_close(RECORD_NOTIFICATION);
|
||||||
|
mifare_nested->notifications = NULL;
|
||||||
|
|
||||||
|
free(mifare_nested);
|
||||||
|
}
|
||||||
|
|
||||||
|
void mifare_nested_blink_start(MifareNested* mifare_nested) {
|
||||||
|
notification_message(mifare_nested->notifications, &mifare_nested_sequence_blink_start_blue);
|
||||||
|
}
|
||||||
|
|
||||||
|
void mifare_nested_blink_calibration_start(MifareNested* mifare_nested) {
|
||||||
|
notification_message(
|
||||||
|
mifare_nested->notifications, &mifare_nested_sequence_blink_start_magenta);
|
||||||
|
}
|
||||||
|
|
||||||
|
void mifare_nested_blink_nonce_collection_start(MifareNested* mifare_nested) {
|
||||||
|
notification_message(mifare_nested->notifications, &mifare_nested_sequence_blink_start_yellow);
|
||||||
|
}
|
||||||
|
|
||||||
|
void mifare_nested_blink_stop(MifareNested* mifare_nested) {
|
||||||
|
notification_message(mifare_nested->notifications, &mifare_nested_sequence_blink_stop);
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t mifare_nested_app(void* p) {
|
||||||
|
UNUSED(p);
|
||||||
|
MifareNested* mifare_nested = mifare_nested_alloc();
|
||||||
|
|
||||||
|
scene_manager_next_scene(mifare_nested->scene_manager, MifareNestedSceneStart);
|
||||||
|
|
||||||
|
view_dispatcher_run(mifare_nested->view_dispatcher);
|
||||||
|
|
||||||
|
mifare_nested_free(mifare_nested);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
3
applications/external/mifare_nested/mifare_nested.h
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
typedef struct MifareNested MifareNested;
|
||||||
180
applications/external/mifare_nested/mifare_nested_i.h
vendored
Normal file
@@ -0,0 +1,180 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "mifare_nested.h"
|
||||||
|
#include "mifare_nested_worker.h"
|
||||||
|
#include "lib/nested/nested.h"
|
||||||
|
#include <furi.h>
|
||||||
|
#include <gui/gui.h>
|
||||||
|
#include <gui/view_dispatcher.h>
|
||||||
|
#include <gui/scene_manager.h>
|
||||||
|
#include <notification/notification_messages.h>
|
||||||
|
#include <gui/modules/submenu.h>
|
||||||
|
#include <gui/modules/popup.h>
|
||||||
|
#include <gui/modules/loading.h>
|
||||||
|
#include <gui/modules/text_input.h>
|
||||||
|
#include <gui/modules/widget.h>
|
||||||
|
#include <input/input.h>
|
||||||
|
#include "scenes/mifare_nested_scene.h"
|
||||||
|
#include <storage/storage.h>
|
||||||
|
#include <lib/toolbox/path.h>
|
||||||
|
#include <lib/nfc/nfc_device.h>
|
||||||
|
#include <lib/toolbox/value_index.h>
|
||||||
|
#include <gui/modules/variable_item_list.h>
|
||||||
|
#include "mifare_nested_icons.h"
|
||||||
|
|
||||||
|
#define NESTED_VERSION_APP "1.4.6"
|
||||||
|
#define NESTED_GITHUB_LINK "https://github.com/AloneLiberty/FlipperNested"
|
||||||
|
#define NESTED_RECOVER_KEYS_GITHUB_LINK "https://github.com/AloneLiberty/FlipperNestedRecovery"
|
||||||
|
#define NESTED_NONCE_FORMAT_VERSION "3"
|
||||||
|
#define NESTED_AUTHOR "@AloneLiberty (t.me/libertydev)"
|
||||||
|
|
||||||
|
enum MifareNestedCustomEvent {
|
||||||
|
// Reserve first 100 events for button types and indexes, starting from 0
|
||||||
|
MifareNestedCustomEventReserved = 100,
|
||||||
|
|
||||||
|
MifareNestedCustomEventViewExit,
|
||||||
|
MifareNestedCustomEventWorkerExit,
|
||||||
|
MifareNestedCustomEventByteInputDone,
|
||||||
|
MifareNestedCustomEventTextInputDone,
|
||||||
|
MifareNestedCustomEventSceneSettingLock
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef void (*NestedCallback)(void* context);
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
FuriMutex* mutex;
|
||||||
|
FuriMessageQueue* event_queue;
|
||||||
|
ViewPort* view_port;
|
||||||
|
View* view;
|
||||||
|
NestedCallback callback;
|
||||||
|
void* context;
|
||||||
|
} NestedState;
|
||||||
|
|
||||||
|
typedef void (*CheckKeysCallback)(void* context);
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
FuriMutex* mutex;
|
||||||
|
FuriMessageQueue* event_queue;
|
||||||
|
ViewPort* view_port;
|
||||||
|
View* view;
|
||||||
|
CheckKeysCallback callback;
|
||||||
|
void* context;
|
||||||
|
} CheckKeysState;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
EventTypeTick,
|
||||||
|
EventTypeKey,
|
||||||
|
} EventType;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
EventType type;
|
||||||
|
InputEvent input;
|
||||||
|
} PluginEvent;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
bool only_hardnested;
|
||||||
|
} MifareNestedSettings;
|
||||||
|
|
||||||
|
typedef enum { NestedRunIdle, NestedRunCheckKeys, NestedRunAttack } NestedRunNext;
|
||||||
|
|
||||||
|
struct MifareNested {
|
||||||
|
MifareNestedWorker* worker;
|
||||||
|
ViewDispatcher* view_dispatcher;
|
||||||
|
Gui* gui;
|
||||||
|
NotificationApp* notifications;
|
||||||
|
SceneManager* scene_manager;
|
||||||
|
NfcDevice* nfc_dev;
|
||||||
|
VariableItemList* variable_item_list;
|
||||||
|
MifareNestedSettings* settings;
|
||||||
|
FuriString* text_box_store;
|
||||||
|
|
||||||
|
// Common Views
|
||||||
|
Submenu* submenu;
|
||||||
|
Popup* popup;
|
||||||
|
Loading* loading;
|
||||||
|
TextInput* text_input;
|
||||||
|
Widget* widget;
|
||||||
|
|
||||||
|
NonceList_t* nonces;
|
||||||
|
KeyInfo_t* keys;
|
||||||
|
|
||||||
|
NestedState* nested_state;
|
||||||
|
CheckKeysState* keys_state;
|
||||||
|
|
||||||
|
MifareNestedWorkerState collecting_type;
|
||||||
|
|
||||||
|
NestedRunNext run;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
MifareNestedViewMenu,
|
||||||
|
MifareNestedViewPopup,
|
||||||
|
MifareNestedViewLoading,
|
||||||
|
MifareNestedViewTextInput,
|
||||||
|
MifareNestedViewWidget,
|
||||||
|
MifareNestedViewVariableList,
|
||||||
|
MifareNestedViewCollecting,
|
||||||
|
MifareNestedViewCheckKeys,
|
||||||
|
} MifareNestedView;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
FuriString* header;
|
||||||
|
uint32_t keys_count;
|
||||||
|
uint32_t nonces_collected;
|
||||||
|
uint32_t hardnested_states;
|
||||||
|
bool lost_tag;
|
||||||
|
bool calibrating;
|
||||||
|
bool need_prediction;
|
||||||
|
bool hardnested;
|
||||||
|
} NestedAttackViewModel;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
FuriString* header;
|
||||||
|
uint32_t keys_count;
|
||||||
|
uint32_t keys_checked;
|
||||||
|
uint32_t keys_found;
|
||||||
|
uint32_t keys_total;
|
||||||
|
bool lost_tag;
|
||||||
|
bool processing_keys;
|
||||||
|
} CheckKeysViewModel;
|
||||||
|
|
||||||
|
static const NotificationSequence mifare_nested_sequence_blink_start_blue = {
|
||||||
|
&message_blink_start_10,
|
||||||
|
&message_blink_set_color_blue,
|
||||||
|
&message_do_not_reset,
|
||||||
|
NULL,
|
||||||
|
};
|
||||||
|
|
||||||
|
static const NotificationSequence mifare_nested_sequence_blink_start_magenta = {
|
||||||
|
&message_blink_start_10,
|
||||||
|
&message_blink_set_color_magenta,
|
||||||
|
&message_do_not_reset,
|
||||||
|
NULL,
|
||||||
|
};
|
||||||
|
|
||||||
|
static const NotificationSequence mifare_nested_sequence_blink_start_yellow = {
|
||||||
|
&message_blink_start_10,
|
||||||
|
&message_blink_set_color_yellow,
|
||||||
|
&message_do_not_reset,
|
||||||
|
NULL,
|
||||||
|
};
|
||||||
|
|
||||||
|
static const NotificationSequence mifare_nested_sequence_blink_stop = {
|
||||||
|
&message_blink_stop,
|
||||||
|
NULL,
|
||||||
|
};
|
||||||
|
|
||||||
|
MifareNested* mifare_nested_alloc();
|
||||||
|
|
||||||
|
void mifare_nested_text_store_set(MifareNested* mifare_nested, const char* text, ...);
|
||||||
|
|
||||||
|
void mifare_nested_text_store_clear(MifareNested* mifare_nested);
|
||||||
|
|
||||||
|
void mifare_nested_blink_start(MifareNested* mifare_nested);
|
||||||
|
|
||||||
|
void mifare_nested_blink_calibration_start(MifareNested* mifare_nested);
|
||||||
|
|
||||||
|
void mifare_nested_blink_nonce_collection_start(MifareNested* mifare_nested);
|
||||||
|
|
||||||
|
void mifare_nested_blink_stop(MifareNested* mifare_nested);
|
||||||
|
|
||||||
|
void mifare_nested_show_loading_popup(void* context, bool show);
|
||||||
1663
applications/external/mifare_nested/mifare_nested_worker.c
vendored
Normal file
89
applications/external/mifare_nested/mifare_nested_worker.h
vendored
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <lib/nfc/nfc_device.h>
|
||||||
|
|
||||||
|
#define NESTED_FOLDER EXT_PATH("nfc/.nested")
|
||||||
|
|
||||||
|
typedef struct MifareNestedWorker MifareNestedWorker;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
MifareNestedWorkerStateReady,
|
||||||
|
|
||||||
|
MifareNestedWorkerStateCheck,
|
||||||
|
MifareNestedWorkerStateCollecting,
|
||||||
|
MifareNestedWorkerStateCollectingStatic,
|
||||||
|
MifareNestedWorkerStateCollectingHard,
|
||||||
|
MifareNestedWorkerStateValidating,
|
||||||
|
|
||||||
|
MifareNestedWorkerStateStop,
|
||||||
|
} MifareNestedWorkerState;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
MifareNestedWorkerEventReserved = 1000,
|
||||||
|
|
||||||
|
MifareNestedWorkerEventNoTagDetected,
|
||||||
|
MifareNestedWorkerEventNoncesCollected,
|
||||||
|
MifareNestedWorkerEventCollecting,
|
||||||
|
|
||||||
|
MifareNestedWorkerEventNewNonce,
|
||||||
|
MifareNestedWorkerEventKeyChecked,
|
||||||
|
MifareNestedWorkerEventKeysFound,
|
||||||
|
MifareNestedWorkerEventNeedKey,
|
||||||
|
MifareNestedWorkerEventAttackFailed,
|
||||||
|
MifareNestedWorkerEventCalibrating,
|
||||||
|
MifareNestedWorkerEventStaticEncryptedNonce,
|
||||||
|
MifareNestedWorkerEventNeedPrediction,
|
||||||
|
MifareNestedWorkerEventProcessingKeys,
|
||||||
|
MifareNestedWorkerEventNeedKeyRecovery,
|
||||||
|
MifareNestedWorkerEventNeedCollection,
|
||||||
|
MifareNestedWorkerEventHardnestedStatesFound
|
||||||
|
} MifareNestedWorkerEvent;
|
||||||
|
|
||||||
|
typedef bool (*MifareNestedWorkerCallback)(MifareNestedWorkerEvent event, void* context);
|
||||||
|
|
||||||
|
MifareNestedWorker* mifare_nested_worker_alloc();
|
||||||
|
|
||||||
|
void mifare_nested_worker_change_state(
|
||||||
|
MifareNestedWorker* mifare_nested_worker,
|
||||||
|
MifareNestedWorkerState state);
|
||||||
|
|
||||||
|
void mifare_nested_worker_free(MifareNestedWorker* mifare_nested_worker);
|
||||||
|
|
||||||
|
void mifare_nested_worker_stop(MifareNestedWorker* mifare_nested_worker);
|
||||||
|
|
||||||
|
void mifare_nested_worker_start(
|
||||||
|
MifareNestedWorker* mifare_nested_worker,
|
||||||
|
MifareNestedWorkerState state,
|
||||||
|
NfcDeviceData* dev_data,
|
||||||
|
MifareNestedWorkerCallback callback,
|
||||||
|
void* context);
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint32_t key_type;
|
||||||
|
uint32_t block;
|
||||||
|
uint32_t target_nt[2];
|
||||||
|
uint32_t target_ks[2];
|
||||||
|
uint8_t parity[2][4];
|
||||||
|
bool collected;
|
||||||
|
bool skipped;
|
||||||
|
bool hardnested;
|
||||||
|
} Nonces;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint32_t cuid;
|
||||||
|
uint32_t sector_count;
|
||||||
|
// 40 (or 16/5) sectors, 2 keys (A/B), 3 tries
|
||||||
|
Nonces* nonces[40][2][3];
|
||||||
|
uint32_t tries;
|
||||||
|
// unique first bytes
|
||||||
|
uint32_t hardnested_states;
|
||||||
|
} NonceList_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint32_t total_keys;
|
||||||
|
uint32_t checked_keys;
|
||||||
|
uint32_t found_keys;
|
||||||
|
uint32_t added_keys;
|
||||||
|
uint32_t sector_keys;
|
||||||
|
bool tag_lost;
|
||||||
|
} KeyInfo_t;
|
||||||
28
applications/external/mifare_nested/mifare_nested_worker_i.h
vendored
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <furi.h>
|
||||||
|
#include "mifare_nested_i.h"
|
||||||
|
#include "mifare_nested_worker.h"
|
||||||
|
|
||||||
|
struct MifareNestedWorker {
|
||||||
|
FuriThread* thread;
|
||||||
|
|
||||||
|
NfcDeviceData* dev_data;
|
||||||
|
|
||||||
|
MifareNestedWorkerCallback callback;
|
||||||
|
MifareNested* context;
|
||||||
|
|
||||||
|
MifareNestedWorkerState state;
|
||||||
|
};
|
||||||
|
|
||||||
|
int32_t mifare_nested_worker_task(void* context);
|
||||||
|
|
||||||
|
void mifare_nested_worker_check(MifareNestedWorker* mifare_nested_worker);
|
||||||
|
|
||||||
|
void mifare_nested_worker_collect_nonces(MifareNestedWorker* mifare_nested_worker);
|
||||||
|
|
||||||
|
void mifare_nested_worker_collect_nonces_static(MifareNestedWorker* mifare_nested_worker);
|
||||||
|
|
||||||
|
void mifare_nested_worker_collect_nonces_hard(MifareNestedWorker* mifare_nested_worker);
|
||||||
|
|
||||||
|
void mifare_nested_worker_check_keys(MifareNestedWorker* mifare_nested_worker);
|
||||||
30
applications/external/mifare_nested/scenes/mifare_nested_scene.c
vendored
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
#include "mifare_nested_scene.h"
|
||||||
|
|
||||||
|
// Generate scene on_enter handlers array
|
||||||
|
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_enter,
|
||||||
|
void (*const mifare_nested_on_enter_handlers[])(void*) = {
|
||||||
|
#include "mifare_nested_scene_config.h"
|
||||||
|
};
|
||||||
|
#undef ADD_SCENE
|
||||||
|
|
||||||
|
// Generate scene on_event handlers array
|
||||||
|
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_event,
|
||||||
|
bool (*const mifare_nested_on_event_handlers[])(void* context, SceneManagerEvent event) = {
|
||||||
|
#include "mifare_nested_scene_config.h"
|
||||||
|
};
|
||||||
|
#undef ADD_SCENE
|
||||||
|
|
||||||
|
// Generate scene on_exit handlers array
|
||||||
|
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_exit,
|
||||||
|
void (*const mifare_nested_on_exit_handlers[])(void* context) = {
|
||||||
|
#include "mifare_nested_scene_config.h"
|
||||||
|
};
|
||||||
|
#undef ADD_SCENE
|
||||||
|
|
||||||
|
// Initialize scene handlers configuration structure
|
||||||
|
const SceneManagerHandlers mifare_nested_scene_handlers = {
|
||||||
|
.on_enter_handlers = mifare_nested_on_enter_handlers,
|
||||||
|
.on_event_handlers = mifare_nested_on_event_handlers,
|
||||||
|
.on_exit_handlers = mifare_nested_on_exit_handlers,
|
||||||
|
.scene_num = MifareNestedSceneNum,
|
||||||
|
};
|
||||||
29
applications/external/mifare_nested/scenes/mifare_nested_scene.h
vendored
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <gui/scene_manager.h>
|
||||||
|
|
||||||
|
// Generate scene id and total number
|
||||||
|
#define ADD_SCENE(prefix, name, id) MifareNestedScene##id,
|
||||||
|
typedef enum {
|
||||||
|
#include "mifare_nested_scene_config.h"
|
||||||
|
MifareNestedSceneNum,
|
||||||
|
} MifareNestedScene;
|
||||||
|
#undef ADD_SCENE
|
||||||
|
|
||||||
|
extern const SceneManagerHandlers mifare_nested_scene_handlers;
|
||||||
|
|
||||||
|
// Generate scene on_enter handlers declaration
|
||||||
|
#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_enter(void*);
|
||||||
|
#include "mifare_nested_scene_config.h"
|
||||||
|
#undef ADD_SCENE
|
||||||
|
|
||||||
|
// Generate scene on_event handlers declaration
|
||||||
|
#define ADD_SCENE(prefix, name, id) \
|
||||||
|
bool prefix##_scene_##name##_on_event(void* context, SceneManagerEvent event);
|
||||||
|
#include "mifare_nested_scene_config.h"
|
||||||
|
#undef ADD_SCENE
|
||||||
|
|
||||||
|
// Generate scene on_exit handlers declaration
|
||||||
|
#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_exit(void* context);
|
||||||
|
#include "mifare_nested_scene_config.h"
|
||||||
|
#undef ADD_SCENE
|
||||||
77
applications/external/mifare_nested/scenes/mifare_nested_scene_about.c
vendored
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
#include "../mifare_nested_i.h"
|
||||||
|
|
||||||
|
void mifare_nested_scene_about_widget_callback(GuiButtonType result, InputType type, void* context) {
|
||||||
|
MifareNested* mifare_nested = context;
|
||||||
|
if(type == InputTypeShort) {
|
||||||
|
view_dispatcher_send_custom_event(mifare_nested->view_dispatcher, result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void mifare_nested_scene_about_on_enter(void* context) {
|
||||||
|
MifareNested* mifare_nested = context;
|
||||||
|
|
||||||
|
FuriString* temp_str;
|
||||||
|
temp_str = furi_string_alloc();
|
||||||
|
furi_string_printf(temp_str, "\e#%s\n", "Information");
|
||||||
|
|
||||||
|
furi_string_cat_printf(temp_str, "Version: %s\n", NESTED_VERSION_APP);
|
||||||
|
furi_string_cat_printf(temp_str, "Developed by:\n%s\n\n", NESTED_AUTHOR);
|
||||||
|
furi_string_cat_printf(temp_str, "Github: %s\n\n", NESTED_GITHUB_LINK);
|
||||||
|
|
||||||
|
furi_string_cat_printf(temp_str, "\e#%s\n", "Description");
|
||||||
|
furi_string_cat_printf(
|
||||||
|
temp_str,
|
||||||
|
"Ported Nested attacks\nfrom Proxmark3 (Iceman fork)\nCurrently supported attacks:\n - nested attack\n - static nested attack\n - hard nested attack\n\n");
|
||||||
|
furi_string_cat_printf(
|
||||||
|
temp_str,
|
||||||
|
"You will need desktop app to recover keys from collected nonces: %s\n\n",
|
||||||
|
NESTED_RECOVER_KEYS_GITHUB_LINK);
|
||||||
|
furi_string_cat_printf(temp_str, "\e#%s\n", "Quick guide");
|
||||||
|
furi_string_cat_printf(temp_str, "1. Install key recovery script on PC:\n");
|
||||||
|
furi_string_cat_printf(temp_str, "pip install FlipperNested\n");
|
||||||
|
furi_string_cat_printf(temp_str, "2. Connect Flipper Zero to PC\n");
|
||||||
|
furi_string_cat_printf(temp_str, "3. Run key recovery:\n");
|
||||||
|
furi_string_cat_printf(temp_str, "FlipperNested");
|
||||||
|
|
||||||
|
widget_add_text_box_element(
|
||||||
|
mifare_nested->widget,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
128,
|
||||||
|
14,
|
||||||
|
AlignCenter,
|
||||||
|
AlignBottom,
|
||||||
|
"\e#\e! \e!\n",
|
||||||
|
false);
|
||||||
|
widget_add_text_box_element(
|
||||||
|
mifare_nested->widget,
|
||||||
|
0,
|
||||||
|
2,
|
||||||
|
128,
|
||||||
|
14,
|
||||||
|
AlignCenter,
|
||||||
|
AlignBottom,
|
||||||
|
"\e#\e! Flipper (Mifare) Nested \e!\n",
|
||||||
|
false);
|
||||||
|
widget_add_text_scroll_element(
|
||||||
|
mifare_nested->widget, 0, 16, 128, 50, furi_string_get_cstr(temp_str));
|
||||||
|
furi_string_free(temp_str);
|
||||||
|
|
||||||
|
view_dispatcher_switch_to_view(mifare_nested->view_dispatcher, MifareNestedViewWidget);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool mifare_nested_scene_about_on_event(void* context, SceneManagerEvent event) {
|
||||||
|
MifareNested* mifare_nested = context;
|
||||||
|
bool consumed = false;
|
||||||
|
UNUSED(mifare_nested);
|
||||||
|
UNUSED(event);
|
||||||
|
|
||||||
|
return consumed;
|
||||||
|
}
|
||||||
|
|
||||||
|
void mifare_nested_scene_about_on_exit(void* context) {
|
||||||
|
MifareNested* mifare_nested = context;
|
||||||
|
|
||||||
|
// Clear views
|
||||||
|
widget_reset(mifare_nested->widget);
|
||||||
|
}
|
||||||
76
applications/external/mifare_nested/scenes/mifare_nested_scene_added_keys.c
vendored
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
#include "../mifare_nested_i.h"
|
||||||
|
|
||||||
|
void mifare_nested_scene_added_keys_widget_callback(
|
||||||
|
GuiButtonType result,
|
||||||
|
InputType type,
|
||||||
|
void* context) {
|
||||||
|
MifareNested* mifare_nested = context;
|
||||||
|
if(type == InputTypeShort) {
|
||||||
|
view_dispatcher_send_custom_event(mifare_nested->view_dispatcher, result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void mifare_nested_scene_added_keys_on_enter(void* context) {
|
||||||
|
MifareNested* mifare_nested = context;
|
||||||
|
KeyInfo_t* key_info = mifare_nested->keys;
|
||||||
|
Widget* widget = mifare_nested->widget;
|
||||||
|
char draw_str[32] = {};
|
||||||
|
char append[5] = {'k', 'e', 'y', ' ', '\0'};
|
||||||
|
if(key_info->added_keys != 1) {
|
||||||
|
append[3] = 's';
|
||||||
|
}
|
||||||
|
|
||||||
|
widget_add_string_element(
|
||||||
|
widget, 0, 0, AlignLeft, AlignTop, FontPrimary, "Results of key recovery");
|
||||||
|
|
||||||
|
if(key_info->added_keys != 0) {
|
||||||
|
snprintf(draw_str, sizeof(draw_str), "Added: %lu %s", key_info->added_keys, append);
|
||||||
|
notification_message(mifare_nested->notifications, &sequence_success);
|
||||||
|
widget_add_icon_element(widget, 52, 17, &I_DolphinSuccess);
|
||||||
|
} else {
|
||||||
|
snprintf(draw_str, sizeof(draw_str), "No new keys were added");
|
||||||
|
widget_add_string_element(
|
||||||
|
widget, 0, 22, AlignLeft, AlignTop, FontSecondary, "Try running \"Nested attack\"");
|
||||||
|
widget_add_string_element(widget, 0, 32, AlignLeft, AlignTop, FontSecondary, "again");
|
||||||
|
notification_message(mifare_nested->notifications, &sequence_error);
|
||||||
|
}
|
||||||
|
|
||||||
|
widget_add_string_element(widget, 0, 12, AlignLeft, AlignTop, FontSecondary, draw_str);
|
||||||
|
widget_add_button_element(
|
||||||
|
widget,
|
||||||
|
GuiButtonTypeLeft,
|
||||||
|
"Back",
|
||||||
|
mifare_nested_scene_added_keys_widget_callback,
|
||||||
|
mifare_nested);
|
||||||
|
|
||||||
|
free(key_info);
|
||||||
|
|
||||||
|
KeyInfo_t* new_key_info = malloc(sizeof(KeyInfo_t));
|
||||||
|
mifare_nested->keys = new_key_info;
|
||||||
|
|
||||||
|
// Setup and start worker
|
||||||
|
view_dispatcher_switch_to_view(mifare_nested->view_dispatcher, MifareNestedViewWidget);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool mifare_nested_scene_added_keys_on_event(void* context, SceneManagerEvent event) {
|
||||||
|
MifareNested* mifare_nested = context;
|
||||||
|
bool consumed = false;
|
||||||
|
|
||||||
|
if(event.type == SceneManagerEventTypeCustom) {
|
||||||
|
if(event.event == GuiButtonTypeCenter || event.event == GuiButtonTypeLeft) {
|
||||||
|
scene_manager_search_and_switch_to_previous_scene(mifare_nested->scene_manager, 0);
|
||||||
|
consumed = true;
|
||||||
|
}
|
||||||
|
} else if(event.type == SceneManagerEventTypeBack) {
|
||||||
|
scene_manager_search_and_switch_to_previous_scene(mifare_nested->scene_manager, 0);
|
||||||
|
consumed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return consumed;
|
||||||
|
}
|
||||||
|
|
||||||
|
void mifare_nested_scene_added_keys_on_exit(void* context) {
|
||||||
|
MifareNested* mifare_nested = context;
|
||||||
|
|
||||||
|
widget_reset(mifare_nested->widget);
|
||||||
|
}
|
||||||
102
applications/external/mifare_nested/scenes/mifare_nested_scene_check.c
vendored
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
#include "../mifare_nested_i.h"
|
||||||
|
|
||||||
|
enum {
|
||||||
|
MifareNestedSceneCheckStateTagSearch,
|
||||||
|
MifareNestedSceneCheckStateTagFound,
|
||||||
|
};
|
||||||
|
|
||||||
|
bool mifare_nested_check_worker_callback(MifareNestedWorkerEvent event, void* context) {
|
||||||
|
furi_assert(context);
|
||||||
|
|
||||||
|
MifareNested* mifare_nested = context;
|
||||||
|
view_dispatcher_send_custom_event(mifare_nested->view_dispatcher, event);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void mifare_nested_scene_check_setup_view(MifareNested* mifare_nested) {
|
||||||
|
Popup* popup = mifare_nested->popup;
|
||||||
|
popup_reset(popup);
|
||||||
|
uint32_t state =
|
||||||
|
scene_manager_get_scene_state(mifare_nested->scene_manager, MifareNestedSceneCheck);
|
||||||
|
|
||||||
|
if(state == MifareNestedSceneCheckStateTagSearch) {
|
||||||
|
popup_set_icon(mifare_nested->popup, 0, 8, &I_ApplyTag);
|
||||||
|
popup_set_text(
|
||||||
|
mifare_nested->popup, "Apply tag to\nthe back", 128, 32, AlignRight, AlignCenter);
|
||||||
|
} else {
|
||||||
|
popup_set_icon(popup, 12, 23, &I_Loading);
|
||||||
|
popup_set_header(popup, "Checking\nDon't move...", 52, 32, AlignLeft, AlignCenter);
|
||||||
|
}
|
||||||
|
|
||||||
|
view_dispatcher_switch_to_view(mifare_nested->view_dispatcher, MifareNestedViewPopup);
|
||||||
|
}
|
||||||
|
|
||||||
|
void mifare_nested_scene_check_on_enter(void* context) {
|
||||||
|
MifareNested* mifare_nested = context;
|
||||||
|
|
||||||
|
scene_manager_set_scene_state(
|
||||||
|
mifare_nested->scene_manager,
|
||||||
|
MifareNestedSceneCheck,
|
||||||
|
MifareNestedSceneCheckStateTagSearch);
|
||||||
|
mifare_nested_scene_check_setup_view(mifare_nested);
|
||||||
|
|
||||||
|
// Setup and start worker
|
||||||
|
mifare_nested_worker_start(
|
||||||
|
mifare_nested->worker,
|
||||||
|
MifareNestedWorkerStateCheck,
|
||||||
|
&mifare_nested->nfc_dev->dev_data,
|
||||||
|
mifare_nested_check_worker_callback,
|
||||||
|
mifare_nested);
|
||||||
|
mifare_nested_blink_start(mifare_nested);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool mifare_nested_scene_check_on_event(void* context, SceneManagerEvent event) {
|
||||||
|
MifareNested* mifare_nested = context;
|
||||||
|
bool consumed = false;
|
||||||
|
|
||||||
|
if(event.type == SceneManagerEventTypeCustom) {
|
||||||
|
if(event.event == MifareNestedWorkerEventNoncesCollected) {
|
||||||
|
scene_manager_next_scene(
|
||||||
|
mifare_nested->scene_manager, MifareNestedSceneNoncesCollected);
|
||||||
|
consumed = true;
|
||||||
|
} else if(event.event == MifareNestedWorkerEventAttackFailed) {
|
||||||
|
scene_manager_next_scene(mifare_nested->scene_manager, MifareNestedSceneFailed);
|
||||||
|
consumed = true;
|
||||||
|
} else if(event.event == MifareNestedWorkerEventCollecting) {
|
||||||
|
if(mifare_nested->run == NestedRunAttack) {
|
||||||
|
if(mifare_nested->settings->only_hardnested) {
|
||||||
|
FURI_LOG_I("MifareNested", "Using Hard Nested because user settings");
|
||||||
|
mifare_nested->collecting_type = MifareNestedWorkerStateCollectingHard;
|
||||||
|
}
|
||||||
|
scene_manager_next_scene(
|
||||||
|
mifare_nested->scene_manager, MifareNestedSceneCollecting);
|
||||||
|
} else {
|
||||||
|
scene_manager_next_scene(mifare_nested->scene_manager, MifareNestedSceneCheckKeys);
|
||||||
|
}
|
||||||
|
consumed = true;
|
||||||
|
} else if(event.event == MifareNestedWorkerEventNoTagDetected) {
|
||||||
|
scene_manager_set_scene_state(
|
||||||
|
mifare_nested->scene_manager,
|
||||||
|
MifareNestedSceneCheck,
|
||||||
|
MifareNestedSceneCheckStateTagSearch);
|
||||||
|
mifare_nested_scene_check_setup_view(mifare_nested);
|
||||||
|
consumed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return consumed;
|
||||||
|
}
|
||||||
|
|
||||||
|
void mifare_nested_scene_check_on_exit(void* context) {
|
||||||
|
MifareNested* mifare_nested = context;
|
||||||
|
|
||||||
|
mifare_nested_worker_stop(mifare_nested->worker);
|
||||||
|
scene_manager_set_scene_state(
|
||||||
|
mifare_nested->scene_manager,
|
||||||
|
MifareNestedSceneCheck,
|
||||||
|
MifareNestedSceneCheckStateTagSearch);
|
||||||
|
// Clear view
|
||||||
|
popup_reset(mifare_nested->popup);
|
||||||
|
|
||||||
|
mifare_nested_blink_stop(mifare_nested);
|
||||||
|
}
|
||||||
124
applications/external/mifare_nested/scenes/mifare_nested_scene_check_keys.c
vendored
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
#include "../mifare_nested_i.h"
|
||||||
|
|
||||||
|
void mifare_nested_scene_check_keys_widget_callback(
|
||||||
|
GuiButtonType result,
|
||||||
|
InputType type,
|
||||||
|
void* context) {
|
||||||
|
MifareNested* mifare_nested = context;
|
||||||
|
if(type == InputTypeShort) {
|
||||||
|
view_dispatcher_send_custom_event(mifare_nested->view_dispatcher, result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool mifare_nested_check_keys_worker_callback(MifareNestedWorkerEvent event, void* context) {
|
||||||
|
MifareNested* mifare_nested = context;
|
||||||
|
CheckKeysState* plugin_state = mifare_nested->keys_state;
|
||||||
|
|
||||||
|
if(event == MifareNestedWorkerEventKeyChecked) {
|
||||||
|
mifare_nested_blink_nonce_collection_start(mifare_nested);
|
||||||
|
|
||||||
|
KeyInfo_t* key_info = mifare_nested->keys;
|
||||||
|
|
||||||
|
with_view_model(
|
||||||
|
plugin_state->view,
|
||||||
|
CheckKeysViewModel * model,
|
||||||
|
{
|
||||||
|
model->lost_tag = false;
|
||||||
|
model->keys_checked = key_info->checked_keys;
|
||||||
|
model->keys_found = key_info->found_keys;
|
||||||
|
model->keys_total = key_info->sector_keys;
|
||||||
|
model->keys_count = key_info->total_keys;
|
||||||
|
},
|
||||||
|
true);
|
||||||
|
} else if(event == MifareNestedWorkerEventNoTagDetected) {
|
||||||
|
mifare_nested_blink_start(mifare_nested);
|
||||||
|
|
||||||
|
with_view_model(
|
||||||
|
plugin_state->view, CheckKeysViewModel * model, { model->lost_tag = true; }, true);
|
||||||
|
} else if(event == MifareNestedWorkerEventProcessingKeys) {
|
||||||
|
with_view_model(
|
||||||
|
plugin_state->view,
|
||||||
|
CheckKeysViewModel * model,
|
||||||
|
{ model->processing_keys = true; },
|
||||||
|
true);
|
||||||
|
}
|
||||||
|
|
||||||
|
view_dispatcher_send_custom_event(mifare_nested->view_dispatcher, event);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void mifare_nested_scene_check_keys_on_enter(void* context) {
|
||||||
|
MifareNested* mifare_nested = context;
|
||||||
|
CheckKeysState* plugin_state = mifare_nested->keys_state;
|
||||||
|
|
||||||
|
mifare_nested_worker_start(
|
||||||
|
mifare_nested->worker,
|
||||||
|
MifareNestedWorkerStateValidating,
|
||||||
|
&mifare_nested->nfc_dev->dev_data,
|
||||||
|
mifare_nested_check_keys_worker_callback,
|
||||||
|
mifare_nested);
|
||||||
|
|
||||||
|
mifare_nested_blink_start(mifare_nested);
|
||||||
|
|
||||||
|
with_view_model(
|
||||||
|
plugin_state->view,
|
||||||
|
CheckKeysViewModel * model,
|
||||||
|
{
|
||||||
|
model->lost_tag = false;
|
||||||
|
model->processing_keys = false;
|
||||||
|
model->keys_count = 0;
|
||||||
|
model->keys_checked = 0;
|
||||||
|
model->keys_found = 0;
|
||||||
|
},
|
||||||
|
false);
|
||||||
|
|
||||||
|
view_dispatcher_switch_to_view(mifare_nested->view_dispatcher, MifareNestedViewCheckKeys);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool mifare_nested_scene_check_keys_on_event(void* context, SceneManagerEvent event) {
|
||||||
|
MifareNested* mifare_nested = context;
|
||||||
|
|
||||||
|
bool consumed = false;
|
||||||
|
if(event.type == SceneManagerEventTypeCustom) {
|
||||||
|
if(event.event == GuiButtonTypeCenter) {
|
||||||
|
scene_manager_search_and_switch_to_previous_scene(mifare_nested->scene_manager, 0);
|
||||||
|
consumed = true;
|
||||||
|
} else if(event.event == MifareNestedWorkerEventNoncesCollected) {
|
||||||
|
scene_manager_next_scene(
|
||||||
|
mifare_nested->scene_manager, MifareNestedSceneNoncesCollected);
|
||||||
|
consumed = true;
|
||||||
|
} else if(event.event == MifareNestedWorkerEventNeedKey) {
|
||||||
|
scene_manager_next_scene(mifare_nested->scene_manager, MifareNestedSceneNoKeys);
|
||||||
|
consumed = true;
|
||||||
|
} else if(event.event == MifareNestedWorkerEventKeysFound) {
|
||||||
|
scene_manager_next_scene(mifare_nested->scene_manager, MifareNestedSceneAddedKeys);
|
||||||
|
consumed = true;
|
||||||
|
} else if(event.event == MifareNestedWorkerEventNeedKeyRecovery) {
|
||||||
|
scene_manager_next_scene(
|
||||||
|
mifare_nested->scene_manager, MifareNestedSceneNeedKeyRecovery);
|
||||||
|
consumed = true;
|
||||||
|
} else if(event.event == MifareNestedWorkerEventNeedCollection) {
|
||||||
|
scene_manager_next_scene(
|
||||||
|
mifare_nested->scene_manager, MifareNestedSceneNeedCollection);
|
||||||
|
consumed = true;
|
||||||
|
} else if(
|
||||||
|
event.event == MifareNestedWorkerEventKeyChecked ||
|
||||||
|
event.event == MifareNestedWorkerEventNoTagDetected ||
|
||||||
|
event.event == MifareNestedWorkerEventProcessingKeys) {
|
||||||
|
consumed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return consumed;
|
||||||
|
}
|
||||||
|
|
||||||
|
void mifare_nested_scene_check_keys_on_exit(void* context) {
|
||||||
|
MifareNested* mifare_nested = context;
|
||||||
|
mifare_nested_worker_stop(mifare_nested->worker);
|
||||||
|
|
||||||
|
// Clear view
|
||||||
|
mifare_nested_blink_stop(mifare_nested);
|
||||||
|
popup_reset(mifare_nested->popup);
|
||||||
|
widget_reset(mifare_nested->widget);
|
||||||
|
}
|
||||||
154
applications/external/mifare_nested/scenes/mifare_nested_scene_collecting.c
vendored
Normal file
@@ -0,0 +1,154 @@
|
|||||||
|
#include "../mifare_nested_i.h"
|
||||||
|
|
||||||
|
void mifare_nested_scene_collecting_widget_callback(
|
||||||
|
GuiButtonType result,
|
||||||
|
InputType type,
|
||||||
|
void* context) {
|
||||||
|
MifareNested* mifare_nested = context;
|
||||||
|
if(type == InputTypeShort) {
|
||||||
|
view_dispatcher_send_custom_event(mifare_nested->view_dispatcher, result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool mifare_nested_collecting_worker_callback(MifareNestedWorkerEvent event, void* context) {
|
||||||
|
MifareNested* mifare_nested = context;
|
||||||
|
NestedState* plugin_state = mifare_nested->nested_state;
|
||||||
|
|
||||||
|
if(event == MifareNestedWorkerEventNewNonce) {
|
||||||
|
mifare_nested_blink_nonce_collection_start(mifare_nested);
|
||||||
|
|
||||||
|
uint8_t collected = 0;
|
||||||
|
NonceList_t* nonces = mifare_nested->nonces;
|
||||||
|
for(uint8_t tries = 0; tries < nonces->tries; tries++) {
|
||||||
|
for(uint8_t sector = 0; sector < nonces->sector_count; sector++) {
|
||||||
|
for(uint8_t keyType = 0; keyType < 2; keyType++) {
|
||||||
|
Nonces* info = nonces->nonces[sector][keyType][tries];
|
||||||
|
if(info->collected) {
|
||||||
|
collected++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
with_view_model(
|
||||||
|
plugin_state->view,
|
||||||
|
NestedAttackViewModel * model,
|
||||||
|
{
|
||||||
|
model->calibrating = false;
|
||||||
|
model->lost_tag = false;
|
||||||
|
model->nonces_collected = collected;
|
||||||
|
model->keys_count = nonces->sector_count * nonces->tries * 2;
|
||||||
|
},
|
||||||
|
true);
|
||||||
|
} else if(event == MifareNestedWorkerEventNoTagDetected) {
|
||||||
|
mifare_nested_blink_start(mifare_nested);
|
||||||
|
|
||||||
|
with_view_model(
|
||||||
|
plugin_state->view, NestedAttackViewModel * model, { model->lost_tag = true; }, true);
|
||||||
|
} else if(event == MifareNestedWorkerEventCalibrating) {
|
||||||
|
mifare_nested_blink_calibration_start(mifare_nested);
|
||||||
|
|
||||||
|
with_view_model(
|
||||||
|
plugin_state->view,
|
||||||
|
NestedAttackViewModel * model,
|
||||||
|
{
|
||||||
|
model->calibrating = true;
|
||||||
|
model->lost_tag = false;
|
||||||
|
model->need_prediction = false;
|
||||||
|
model->hardnested = false;
|
||||||
|
},
|
||||||
|
true);
|
||||||
|
} else if(event == MifareNestedWorkerEventNeedPrediction) {
|
||||||
|
with_view_model(
|
||||||
|
plugin_state->view,
|
||||||
|
NestedAttackViewModel * model,
|
||||||
|
{ model->need_prediction = true; },
|
||||||
|
true);
|
||||||
|
} else if(event == MifareNestedWorkerEventHardnestedStatesFound) {
|
||||||
|
NonceList_t* nonces = mifare_nested->nonces;
|
||||||
|
with_view_model(
|
||||||
|
plugin_state->view,
|
||||||
|
NestedAttackViewModel * model,
|
||||||
|
{
|
||||||
|
model->calibrating = false;
|
||||||
|
model->lost_tag = false;
|
||||||
|
model->hardnested = true;
|
||||||
|
model->hardnested_states = nonces->hardnested_states;
|
||||||
|
},
|
||||||
|
true);
|
||||||
|
}
|
||||||
|
|
||||||
|
view_dispatcher_send_custom_event(mifare_nested->view_dispatcher, event);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void mifare_nested_scene_collecting_on_enter(void* context) {
|
||||||
|
MifareNested* mifare_nested = context;
|
||||||
|
NestedState* nested = mifare_nested->nested_state;
|
||||||
|
|
||||||
|
mifare_nested_worker_start(
|
||||||
|
mifare_nested->worker,
|
||||||
|
mifare_nested->collecting_type,
|
||||||
|
&mifare_nested->nfc_dev->dev_data,
|
||||||
|
mifare_nested_collecting_worker_callback,
|
||||||
|
mifare_nested);
|
||||||
|
|
||||||
|
mifare_nested_blink_start(mifare_nested);
|
||||||
|
|
||||||
|
with_view_model(
|
||||||
|
nested->view,
|
||||||
|
NestedAttackViewModel * model,
|
||||||
|
{
|
||||||
|
model->lost_tag = false;
|
||||||
|
model->nonces_collected = 0;
|
||||||
|
},
|
||||||
|
false);
|
||||||
|
|
||||||
|
view_dispatcher_switch_to_view(mifare_nested->view_dispatcher, MifareNestedViewCollecting);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool mifare_nested_scene_collecting_on_event(void* context, SceneManagerEvent event) {
|
||||||
|
MifareNested* mifare_nested = context;
|
||||||
|
|
||||||
|
bool consumed = false;
|
||||||
|
if(event.type == SceneManagerEventTypeCustom) {
|
||||||
|
if(event.event == GuiButtonTypeCenter) {
|
||||||
|
scene_manager_search_and_switch_to_previous_scene(mifare_nested->scene_manager, 0);
|
||||||
|
consumed = true;
|
||||||
|
} else if(event.event == MifareNestedWorkerEventNoncesCollected) {
|
||||||
|
scene_manager_next_scene(
|
||||||
|
mifare_nested->scene_manager, MifareNestedSceneNoncesCollected);
|
||||||
|
consumed = true;
|
||||||
|
} else if(event.event == MifareNestedWorkerEventAttackFailed) {
|
||||||
|
scene_manager_next_scene(mifare_nested->scene_manager, MifareNestedSceneFailed);
|
||||||
|
consumed = true;
|
||||||
|
} else if(event.event == MifareNestedWorkerEventNeedKey) {
|
||||||
|
scene_manager_next_scene(mifare_nested->scene_manager, MifareNestedSceneNoKeys);
|
||||||
|
consumed = true;
|
||||||
|
} else if(event.event == MifareNestedWorkerEventStaticEncryptedNonce) {
|
||||||
|
scene_manager_next_scene(
|
||||||
|
mifare_nested->scene_manager, MifareNestedSceneStaticEncryptedNonce);
|
||||||
|
consumed = true;
|
||||||
|
} else if(
|
||||||
|
event.event == MifareNestedWorkerEventNewNonce ||
|
||||||
|
event.event == MifareNestedWorkerEventNoTagDetected ||
|
||||||
|
event.event == MifareNestedWorkerEventCalibrating ||
|
||||||
|
event.event == MifareNestedWorkerEventNeedPrediction ||
|
||||||
|
event.event == MifareNestedWorkerEventHardnestedStatesFound) {
|
||||||
|
consumed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return consumed;
|
||||||
|
}
|
||||||
|
|
||||||
|
void mifare_nested_scene_collecting_on_exit(void* context) {
|
||||||
|
MifareNested* mifare_nested = context;
|
||||||
|
mifare_nested_worker_stop(mifare_nested->worker);
|
||||||
|
|
||||||
|
// Clear view
|
||||||
|
mifare_nested_blink_stop(mifare_nested);
|
||||||
|
popup_reset(mifare_nested->popup);
|
||||||
|
widget_reset(mifare_nested->widget);
|
||||||
|
}
|
||||||
13
applications/external/mifare_nested/scenes/mifare_nested_scene_config.h
vendored
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
ADD_SCENE(mifare_nested, start, Start)
|
||||||
|
ADD_SCENE(mifare_nested, check, Check)
|
||||||
|
ADD_SCENE(mifare_nested, nonces_collected, NoncesCollected)
|
||||||
|
ADD_SCENE(mifare_nested, collecting, Collecting)
|
||||||
|
ADD_SCENE(mifare_nested, no_keys, NoKeys)
|
||||||
|
ADD_SCENE(mifare_nested, check_keys, CheckKeys)
|
||||||
|
ADD_SCENE(mifare_nested, added_keys, AddedKeys)
|
||||||
|
ADD_SCENE(mifare_nested, failed, Failed)
|
||||||
|
ADD_SCENE(mifare_nested, about, About)
|
||||||
|
ADD_SCENE(mifare_nested, static_encrypted_nonce, StaticEncryptedNonce)
|
||||||
|
ADD_SCENE(mifare_nested, need_key_recovery, NeedKeyRecovery)
|
||||||
|
ADD_SCENE(mifare_nested, need_collection, NeedCollection)
|
||||||
|
ADD_SCENE(mifare_nested, settings, Settings)
|
||||||
59
applications/external/mifare_nested/scenes/mifare_nested_scene_failed.c
vendored
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
#include "../mifare_nested_i.h"
|
||||||
|
|
||||||
|
void mifare_nested_scene_failed_widget_callback(
|
||||||
|
GuiButtonType result,
|
||||||
|
InputType type,
|
||||||
|
void* context) {
|
||||||
|
MifareNested* mifare_nested = context;
|
||||||
|
if(type == InputTypeShort) {
|
||||||
|
view_dispatcher_send_custom_event(mifare_nested->view_dispatcher, result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void mifare_nested_scene_failed_on_enter(void* context) {
|
||||||
|
MifareNested* mifare_nested = context;
|
||||||
|
Widget* widget = mifare_nested->widget;
|
||||||
|
|
||||||
|
notification_message(mifare_nested->notifications, &sequence_error);
|
||||||
|
|
||||||
|
widget_add_icon_element(widget, 73, 13, &I_DolphinCry);
|
||||||
|
widget_add_string_element(
|
||||||
|
widget, 0, 0, AlignLeft, AlignTop, FontPrimary, "Failed to preform attack");
|
||||||
|
widget_add_string_element(widget, 0, 12, AlignLeft, AlignTop, FontSecondary, "Try running");
|
||||||
|
widget_add_string_element(
|
||||||
|
widget, 0, 22, AlignLeft, AlignTop, FontSecondary, "\"Nested attack\"");
|
||||||
|
widget_add_string_element(widget, 0, 32, AlignLeft, AlignTop, FontSecondary, "again or check");
|
||||||
|
widget_add_string_element(widget, 0, 42, AlignLeft, AlignTop, FontSecondary, "logs");
|
||||||
|
widget_add_button_element(
|
||||||
|
widget,
|
||||||
|
GuiButtonTypeLeft,
|
||||||
|
"Back",
|
||||||
|
mifare_nested_scene_failed_widget_callback,
|
||||||
|
mifare_nested);
|
||||||
|
|
||||||
|
// Setup and start worker
|
||||||
|
view_dispatcher_switch_to_view(mifare_nested->view_dispatcher, MifareNestedViewWidget);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool mifare_nested_scene_failed_on_event(void* context, SceneManagerEvent event) {
|
||||||
|
MifareNested* mifare_nested = context;
|
||||||
|
bool consumed = false;
|
||||||
|
|
||||||
|
if(event.type == SceneManagerEventTypeCustom) {
|
||||||
|
if(event.event == GuiButtonTypeCenter || event.event == GuiButtonTypeLeft) {
|
||||||
|
scene_manager_search_and_switch_to_previous_scene(mifare_nested->scene_manager, 0);
|
||||||
|
consumed = true;
|
||||||
|
}
|
||||||
|
} else if(event.type == SceneManagerEventTypeBack) {
|
||||||
|
scene_manager_search_and_switch_to_previous_scene(mifare_nested->scene_manager, 0);
|
||||||
|
consumed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return consumed;
|
||||||
|
}
|
||||||
|
|
||||||
|
void mifare_nested_scene_failed_on_exit(void* context) {
|
||||||
|
MifareNested* mifare_nested = context;
|
||||||
|
|
||||||
|
widget_reset(mifare_nested->widget);
|
||||||
|
}
|
||||||
56
applications/external/mifare_nested/scenes/mifare_nested_scene_need_collection.c
vendored
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
#include "../mifare_nested_i.h"
|
||||||
|
|
||||||
|
void mifare_nested_scene_need_collection_widget_callback(
|
||||||
|
GuiButtonType result,
|
||||||
|
InputType type,
|
||||||
|
void* context) {
|
||||||
|
MifareNested* mifare_nested = context;
|
||||||
|
if(type == InputTypeShort) {
|
||||||
|
view_dispatcher_send_custom_event(mifare_nested->view_dispatcher, result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void mifare_nested_scene_need_collection_on_enter(void* context) {
|
||||||
|
MifareNested* mifare_nested = context;
|
||||||
|
Widget* widget = mifare_nested->widget;
|
||||||
|
|
||||||
|
notification_message(mifare_nested->notifications, &sequence_error);
|
||||||
|
|
||||||
|
widget_add_icon_element(widget, 73, 13, &I_DolphinCry);
|
||||||
|
widget_add_string_element(
|
||||||
|
widget, 0, 0, AlignLeft, AlignTop, FontPrimary, "Missing collected nonces");
|
||||||
|
widget_add_string_element(
|
||||||
|
widget, 0, 12, AlignLeft, AlignTop, FontSecondary, "Run \"Nested attack\"");
|
||||||
|
widget_add_button_element(
|
||||||
|
widget,
|
||||||
|
GuiButtonTypeLeft,
|
||||||
|
"Back",
|
||||||
|
mifare_nested_scene_need_collection_widget_callback,
|
||||||
|
mifare_nested);
|
||||||
|
|
||||||
|
// Setup and start worker
|
||||||
|
view_dispatcher_switch_to_view(mifare_nested->view_dispatcher, MifareNestedViewWidget);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool mifare_nested_scene_need_collection_on_event(void* context, SceneManagerEvent event) {
|
||||||
|
MifareNested* mifare_nested = context;
|
||||||
|
bool consumed = false;
|
||||||
|
|
||||||
|
if(event.type == SceneManagerEventTypeCustom) {
|
||||||
|
if(event.event == GuiButtonTypeCenter || event.event == GuiButtonTypeLeft) {
|
||||||
|
scene_manager_search_and_switch_to_previous_scene(mifare_nested->scene_manager, 0);
|
||||||
|
consumed = true;
|
||||||
|
}
|
||||||
|
} else if(event.type == SceneManagerEventTypeBack) {
|
||||||
|
scene_manager_search_and_switch_to_previous_scene(mifare_nested->scene_manager, 0);
|
||||||
|
consumed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return consumed;
|
||||||
|
}
|
||||||
|
|
||||||
|
void mifare_nested_scene_need_collection_on_exit(void* context) {
|
||||||
|
MifareNested* mifare_nested = context;
|
||||||
|
|
||||||
|
widget_reset(mifare_nested->widget);
|
||||||
|
}
|
||||||
59
applications/external/mifare_nested/scenes/mifare_nested_scene_need_key_recovery.c
vendored
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
#include "../mifare_nested_i.h"
|
||||||
|
|
||||||
|
void mifare_nested_scene_need_key_recovery_widget_callback(
|
||||||
|
GuiButtonType result,
|
||||||
|
InputType type,
|
||||||
|
void* context) {
|
||||||
|
MifareNested* mifare_nested = context;
|
||||||
|
if(type == InputTypeShort) {
|
||||||
|
view_dispatcher_send_custom_event(mifare_nested->view_dispatcher, result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void mifare_nested_scene_need_key_recovery_on_enter(void* context) {
|
||||||
|
MifareNested* mifare_nested = context;
|
||||||
|
Widget* widget = mifare_nested->widget;
|
||||||
|
|
||||||
|
notification_message(mifare_nested->notifications, &sequence_error);
|
||||||
|
|
||||||
|
widget_add_icon_element(widget, 74, 13, &I_DolphinCry);
|
||||||
|
widget_add_string_element(
|
||||||
|
widget, 0, 0, AlignLeft, AlignTop, FontPrimary, "Missing found keys");
|
||||||
|
widget_add_string_element(
|
||||||
|
widget, 0, 12, AlignLeft, AlignTop, FontSecondary, "First you need to");
|
||||||
|
widget_add_string_element(widget, 0, 22, AlignLeft, AlignTop, FontSecondary, "recover keys");
|
||||||
|
widget_add_string_element(widget, 0, 32, AlignLeft, AlignTop, FontSecondary, "Read \"About\"");
|
||||||
|
widget_add_string_element(widget, 0, 42, AlignLeft, AlignTop, FontSecondary, "for more info");
|
||||||
|
widget_add_button_element(
|
||||||
|
widget,
|
||||||
|
GuiButtonTypeLeft,
|
||||||
|
"Back",
|
||||||
|
mifare_nested_scene_need_key_recovery_widget_callback,
|
||||||
|
mifare_nested);
|
||||||
|
|
||||||
|
// Setup and start worker
|
||||||
|
view_dispatcher_switch_to_view(mifare_nested->view_dispatcher, MifareNestedViewWidget);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool mifare_nested_scene_need_key_recovery_on_event(void* context, SceneManagerEvent event) {
|
||||||
|
MifareNested* mifare_nested = context;
|
||||||
|
bool consumed = false;
|
||||||
|
|
||||||
|
if(event.type == SceneManagerEventTypeCustom) {
|
||||||
|
if(event.event == GuiButtonTypeCenter || event.event == GuiButtonTypeLeft) {
|
||||||
|
scene_manager_search_and_switch_to_previous_scene(mifare_nested->scene_manager, 0);
|
||||||
|
consumed = true;
|
||||||
|
}
|
||||||
|
} else if(event.type == SceneManagerEventTypeBack) {
|
||||||
|
scene_manager_search_and_switch_to_previous_scene(mifare_nested->scene_manager, 0);
|
||||||
|
consumed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return consumed;
|
||||||
|
}
|
||||||
|
|
||||||
|
void mifare_nested_scene_need_key_recovery_on_exit(void* context) {
|
||||||
|
MifareNested* mifare_nested = context;
|
||||||
|
|
||||||
|
widget_reset(mifare_nested->widget);
|
||||||
|
}
|
||||||
61
applications/external/mifare_nested/scenes/mifare_nested_scene_no_keys.c
vendored
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
#include "../mifare_nested_i.h"
|
||||||
|
|
||||||
|
void mifare_nested_scene_no_keys_widget_callback(
|
||||||
|
GuiButtonType result,
|
||||||
|
InputType type,
|
||||||
|
void* context) {
|
||||||
|
MifareNested* mifare_nested = context;
|
||||||
|
if(type == InputTypeShort) {
|
||||||
|
view_dispatcher_send_custom_event(mifare_nested->view_dispatcher, result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void mifare_nested_scene_no_keys_on_enter(void* context) {
|
||||||
|
MifareNested* mifare_nested = context;
|
||||||
|
Widget* widget = mifare_nested->widget;
|
||||||
|
|
||||||
|
notification_message(mifare_nested->notifications, &sequence_success);
|
||||||
|
|
||||||
|
widget_add_icon_element(widget, 73, 13, &I_DolphinCry);
|
||||||
|
widget_add_string_element(widget, 0, 0, AlignLeft, AlignTop, FontPrimary, "No keys found");
|
||||||
|
widget_add_string_element(
|
||||||
|
widget, 0, 12, AlignLeft, AlignTop, FontSecondary, "Scan tag and find at");
|
||||||
|
widget_add_string_element(
|
||||||
|
widget, 0, 22, AlignLeft, AlignTop, FontSecondary, "least one key to");
|
||||||
|
widget_add_string_element(
|
||||||
|
widget, 0, 32, AlignLeft, AlignTop, FontSecondary, "start (save dump");
|
||||||
|
widget_add_string_element(
|
||||||
|
widget, 0, 42, AlignLeft, AlignTop, FontSecondary, "after scanning!)");
|
||||||
|
widget_add_button_element(
|
||||||
|
widget,
|
||||||
|
GuiButtonTypeLeft,
|
||||||
|
"Back",
|
||||||
|
mifare_nested_scene_no_keys_widget_callback,
|
||||||
|
mifare_nested);
|
||||||
|
|
||||||
|
// Setup and start worker
|
||||||
|
view_dispatcher_switch_to_view(mifare_nested->view_dispatcher, MifareNestedViewWidget);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool mifare_nested_scene_no_keys_on_event(void* context, SceneManagerEvent event) {
|
||||||
|
MifareNested* mifare_nested = context;
|
||||||
|
bool consumed = false;
|
||||||
|
|
||||||
|
if(event.type == SceneManagerEventTypeCustom) {
|
||||||
|
if(event.event == GuiButtonTypeCenter || event.event == GuiButtonTypeLeft) {
|
||||||
|
scene_manager_search_and_switch_to_previous_scene(mifare_nested->scene_manager, 0);
|
||||||
|
consumed = true;
|
||||||
|
}
|
||||||
|
} else if(event.type == SceneManagerEventTypeBack) {
|
||||||
|
scene_manager_search_and_switch_to_previous_scene(mifare_nested->scene_manager, 0);
|
||||||
|
consumed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return consumed;
|
||||||
|
}
|
||||||
|
|
||||||
|
void mifare_nested_scene_no_keys_on_exit(void* context) {
|
||||||
|
MifareNested* mifare_nested = context;
|
||||||
|
|
||||||
|
widget_reset(mifare_nested->widget);
|
||||||
|
}
|
||||||
58
applications/external/mifare_nested/scenes/mifare_nested_scene_nonces_collected.c
vendored
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
#include "../mifare_nested_i.h"
|
||||||
|
|
||||||
|
void mifare_nested_scene_nonces_collected_widget_callback(
|
||||||
|
GuiButtonType result,
|
||||||
|
InputType type,
|
||||||
|
void* context) {
|
||||||
|
MifareNested* mifare_nested = context;
|
||||||
|
if(type == InputTypeShort) {
|
||||||
|
view_dispatcher_send_custom_event(mifare_nested->view_dispatcher, result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void mifare_nested_scene_nonces_collected_on_enter(void* context) {
|
||||||
|
MifareNested* mifare_nested = context;
|
||||||
|
Widget* widget = mifare_nested->widget;
|
||||||
|
|
||||||
|
notification_message(mifare_nested->notifications, &sequence_success);
|
||||||
|
|
||||||
|
widget_add_icon_element(widget, 52, 17, &I_DolphinSuccess);
|
||||||
|
widget_add_string_element(widget, 0, 0, AlignLeft, AlignTop, FontPrimary, "Nonces collected");
|
||||||
|
widget_add_string_element(
|
||||||
|
widget, 0, 12, AlignLeft, AlignTop, FontSecondary, "Now you can run");
|
||||||
|
widget_add_string_element(widget, 0, 22, AlignLeft, AlignTop, FontSecondary, "script on your");
|
||||||
|
widget_add_string_element(widget, 0, 32, AlignLeft, AlignTop, FontSecondary, "PC to recover");
|
||||||
|
widget_add_string_element(widget, 0, 42, AlignLeft, AlignTop, FontSecondary, "keys");
|
||||||
|
widget_add_button_element(
|
||||||
|
widget,
|
||||||
|
GuiButtonTypeLeft,
|
||||||
|
"Back",
|
||||||
|
mifare_nested_scene_nonces_collected_widget_callback,
|
||||||
|
mifare_nested);
|
||||||
|
|
||||||
|
// Setup and start worker
|
||||||
|
view_dispatcher_switch_to_view(mifare_nested->view_dispatcher, MifareNestedViewWidget);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool mifare_nested_scene_nonces_collected_on_event(void* context, SceneManagerEvent event) {
|
||||||
|
MifareNested* mifare_nested = context;
|
||||||
|
bool consumed = false;
|
||||||
|
|
||||||
|
if(event.type == SceneManagerEventTypeCustom) {
|
||||||
|
if(event.event == GuiButtonTypeCenter || event.event == GuiButtonTypeLeft) {
|
||||||
|
scene_manager_search_and_switch_to_previous_scene(mifare_nested->scene_manager, 0);
|
||||||
|
consumed = true;
|
||||||
|
}
|
||||||
|
} else if(event.type == SceneManagerEventTypeBack) {
|
||||||
|
scene_manager_search_and_switch_to_previous_scene(mifare_nested->scene_manager, 0);
|
||||||
|
consumed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return consumed;
|
||||||
|
}
|
||||||
|
|
||||||
|
void mifare_nested_scene_nonces_collected_on_exit(void* context) {
|
||||||
|
MifareNested* mifare_nested = context;
|
||||||
|
|
||||||
|
widget_reset(mifare_nested->widget);
|
||||||
|
}
|
||||||
65
applications/external/mifare_nested/scenes/mifare_nested_scene_settings.c
vendored
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
#include "../mifare_nested_i.h"
|
||||||
|
#include <lib/toolbox/value_index.h>
|
||||||
|
|
||||||
|
enum MifareNestedSettingsIndex { MifareNestedIndexBlock, MifareNestedIndexHardNested };
|
||||||
|
|
||||||
|
#define HARD_NESTED_COUNT 2
|
||||||
|
const char* const hard_nested_text[HARD_NESTED_COUNT] = {
|
||||||
|
"No",
|
||||||
|
"Yes",
|
||||||
|
};
|
||||||
|
|
||||||
|
const bool hard_nested_value[HARD_NESTED_COUNT] = {
|
||||||
|
false,
|
||||||
|
true,
|
||||||
|
};
|
||||||
|
|
||||||
|
static void mifare_nested_scene_settings_set_hard_nested(VariableItem* item) {
|
||||||
|
MifareNested* mifare_nested = variable_item_get_context(item);
|
||||||
|
uint8_t index = variable_item_get_current_value_index(item);
|
||||||
|
|
||||||
|
variable_item_set_current_value_text(item, hard_nested_text[index]);
|
||||||
|
mifare_nested->settings->only_hardnested = hard_nested_value[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
void mifare_nested_scene_settings_on_enter(void* context) {
|
||||||
|
MifareNested* mifare_nested = context;
|
||||||
|
VariableItem* item;
|
||||||
|
uint8_t value_index;
|
||||||
|
|
||||||
|
item = variable_item_list_add(
|
||||||
|
mifare_nested->variable_item_list,
|
||||||
|
"Hard Nested only:",
|
||||||
|
HARD_NESTED_COUNT,
|
||||||
|
mifare_nested_scene_settings_set_hard_nested,
|
||||||
|
mifare_nested);
|
||||||
|
|
||||||
|
value_index = value_index_bool(
|
||||||
|
mifare_nested->settings->only_hardnested, hard_nested_value, HARD_NESTED_COUNT);
|
||||||
|
|
||||||
|
variable_item_set_current_value_index(item, value_index);
|
||||||
|
variable_item_set_current_value_text(item, hard_nested_text[value_index]);
|
||||||
|
|
||||||
|
view_dispatcher_switch_to_view(mifare_nested->view_dispatcher, MifareNestedViewVariableList);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool mifare_nested_scene_settings_on_event(void* context, SceneManagerEvent event) {
|
||||||
|
MifareNested* mifare_nested = context;
|
||||||
|
bool consumed = false;
|
||||||
|
|
||||||
|
if(event.type == SceneManagerEventTypeCustom) {
|
||||||
|
if(event.event == MifareNestedCustomEventSceneSettingLock) {
|
||||||
|
scene_manager_previous_scene(mifare_nested->scene_manager);
|
||||||
|
consumed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return consumed;
|
||||||
|
}
|
||||||
|
|
||||||
|
void mifare_nested_scene_settings_on_exit(void* context) {
|
||||||
|
MifareNested* mifare_nested = context;
|
||||||
|
variable_item_list_set_selected_item(mifare_nested->variable_item_list, 0);
|
||||||
|
variable_item_list_reset(mifare_nested->variable_item_list);
|
||||||
|
scene_manager_set_scene_state(mifare_nested->scene_manager, MifareNestedSceneStart, 0);
|
||||||
|
}
|
||||||
84
applications/external/mifare_nested/scenes/mifare_nested_scene_start.c
vendored
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
#include "../mifare_nested_i.h"
|
||||||
|
enum SubmenuIndex {
|
||||||
|
SubmenuIndexCollect,
|
||||||
|
SubmenuIndexCheck,
|
||||||
|
SubmenuIndexSettings,
|
||||||
|
SubmenuIndexAbout
|
||||||
|
};
|
||||||
|
|
||||||
|
void mifare_nested_scene_start_submenu_callback(void* context, uint32_t index) {
|
||||||
|
MifareNested* mifare_nested = context;
|
||||||
|
view_dispatcher_send_custom_event(mifare_nested->view_dispatcher, index);
|
||||||
|
}
|
||||||
|
|
||||||
|
void mifare_nested_scene_start_on_enter(void* context) {
|
||||||
|
MifareNested* mifare_nested = context;
|
||||||
|
|
||||||
|
Submenu* submenu = mifare_nested->submenu;
|
||||||
|
submenu_add_item(
|
||||||
|
submenu,
|
||||||
|
"Nested attack",
|
||||||
|
SubmenuIndexCollect,
|
||||||
|
mifare_nested_scene_start_submenu_callback,
|
||||||
|
mifare_nested);
|
||||||
|
|
||||||
|
submenu_add_item(
|
||||||
|
submenu,
|
||||||
|
"Check found keys",
|
||||||
|
SubmenuIndexCheck,
|
||||||
|
mifare_nested_scene_start_submenu_callback,
|
||||||
|
mifare_nested);
|
||||||
|
|
||||||
|
submenu_add_item(
|
||||||
|
submenu,
|
||||||
|
"Settings",
|
||||||
|
SubmenuIndexSettings,
|
||||||
|
mifare_nested_scene_start_submenu_callback,
|
||||||
|
mifare_nested);
|
||||||
|
|
||||||
|
submenu_add_item(
|
||||||
|
submenu,
|
||||||
|
"About",
|
||||||
|
SubmenuIndexAbout,
|
||||||
|
mifare_nested_scene_start_submenu_callback,
|
||||||
|
mifare_nested);
|
||||||
|
|
||||||
|
submenu_set_selected_item(
|
||||||
|
submenu,
|
||||||
|
scene_manager_get_scene_state(mifare_nested->scene_manager, MifareNestedSceneStart));
|
||||||
|
view_dispatcher_switch_to_view(mifare_nested->view_dispatcher, MifareNestedViewMenu);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool mifare_nested_scene_start_on_event(void* context, SceneManagerEvent event) {
|
||||||
|
MifareNested* mifare_nested = context;
|
||||||
|
bool consumed = false;
|
||||||
|
|
||||||
|
if(event.type == SceneManagerEventTypeCustom) {
|
||||||
|
if(event.event == SubmenuIndexCollect) {
|
||||||
|
mifare_nested->run = NestedRunAttack;
|
||||||
|
scene_manager_next_scene(mifare_nested->scene_manager, MifareNestedSceneCheck);
|
||||||
|
consumed = true;
|
||||||
|
} else if(event.event == SubmenuIndexCheck) {
|
||||||
|
mifare_nested->run = NestedRunCheckKeys;
|
||||||
|
scene_manager_next_scene(mifare_nested->scene_manager, MifareNestedSceneCheck);
|
||||||
|
consumed = true;
|
||||||
|
} else if(event.event == SubmenuIndexSettings) {
|
||||||
|
mifare_nested->keys->found_keys = 123;
|
||||||
|
scene_manager_next_scene(mifare_nested->scene_manager, MifareNestedSceneSettings);
|
||||||
|
consumed = true;
|
||||||
|
} else if(event.event == SubmenuIndexAbout) {
|
||||||
|
scene_manager_next_scene(mifare_nested->scene_manager, MifareNestedSceneAbout);
|
||||||
|
consumed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
scene_manager_set_scene_state(
|
||||||
|
mifare_nested->scene_manager, MifareNestedSceneStart, event.event);
|
||||||
|
}
|
||||||
|
|
||||||
|
return consumed;
|
||||||
|
}
|
||||||
|
|
||||||
|
void mifare_nested_scene_start_on_exit(void* context) {
|
||||||
|
MifareNested* mifare_nested = context;
|
||||||
|
submenu_reset(mifare_nested->submenu);
|
||||||
|
}
|
||||||
58
applications/external/mifare_nested/scenes/mifare_nested_scene_static_encrypted_nonce.c
vendored
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
#include "../mifare_nested_i.h"
|
||||||
|
|
||||||
|
void mifare_nested_scene_static_encrypted_nonce_widget_callback(
|
||||||
|
GuiButtonType result,
|
||||||
|
InputType type,
|
||||||
|
void* context) {
|
||||||
|
MifareNested* mifare_nested = context;
|
||||||
|
if(type == InputTypeShort) {
|
||||||
|
view_dispatcher_send_custom_event(mifare_nested->view_dispatcher, result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void mifare_nested_scene_static_encrypted_nonce_on_enter(void* context) {
|
||||||
|
MifareNested* mifare_nested = context;
|
||||||
|
Widget* widget = mifare_nested->widget;
|
||||||
|
|
||||||
|
notification_message(mifare_nested->notifications, &sequence_error);
|
||||||
|
|
||||||
|
widget_add_icon_element(widget, 73, 12, &I_DolphinCry);
|
||||||
|
widget_add_string_element(
|
||||||
|
widget, 0, 0, AlignLeft, AlignTop, FontPrimary, "Static encrypted nonce");
|
||||||
|
widget_add_string_element(widget, 0, 12, AlignLeft, AlignTop, FontSecondary, "This tag isn't");
|
||||||
|
widget_add_string_element(widget, 0, 22, AlignLeft, AlignTop, FontSecondary, "vulnerable to");
|
||||||
|
widget_add_string_element(widget, 0, 32, AlignLeft, AlignTop, FontSecondary, "Nested attack");
|
||||||
|
|
||||||
|
widget_add_button_element(
|
||||||
|
widget,
|
||||||
|
GuiButtonTypeLeft,
|
||||||
|
"Back",
|
||||||
|
mifare_nested_scene_static_encrypted_nonce_widget_callback,
|
||||||
|
mifare_nested);
|
||||||
|
|
||||||
|
// Setup and start worker
|
||||||
|
view_dispatcher_switch_to_view(mifare_nested->view_dispatcher, MifareNestedViewWidget);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool mifare_nested_scene_static_encrypted_nonce_on_event(void* context, SceneManagerEvent event) {
|
||||||
|
MifareNested* mifare_nested = context;
|
||||||
|
bool consumed = false;
|
||||||
|
|
||||||
|
if(event.type == SceneManagerEventTypeCustom) {
|
||||||
|
if(event.event == GuiButtonTypeCenter || event.event == GuiButtonTypeLeft) {
|
||||||
|
scene_manager_search_and_switch_to_previous_scene(mifare_nested->scene_manager, 0);
|
||||||
|
consumed = true;
|
||||||
|
}
|
||||||
|
} else if(event.type == SceneManagerEventTypeBack) {
|
||||||
|
scene_manager_search_and_switch_to_previous_scene(mifare_nested->scene_manager, 0);
|
||||||
|
consumed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return consumed;
|
||||||
|
}
|
||||||
|
|
||||||
|
void mifare_nested_scene_static_encrypted_nonce_on_exit(void* context) {
|
||||||
|
MifareNested* mifare_nested = context;
|
||||||
|
|
||||||
|
widget_reset(mifare_nested->widget);
|
||||||
|
}
|
||||||
@@ -11,7 +11,7 @@ App(
|
|||||||
stack_size=4 * 1024,
|
stack_size=4 * 1024,
|
||||||
order=30,
|
order=30,
|
||||||
fap_icon="../../../assets/icons/Archive/Nfc_10px.png",
|
fap_icon="../../../assets/icons/Archive/Nfc_10px.png",
|
||||||
fap_category="Tools",
|
fap_category="NFC",
|
||||||
fap_private_libs=[
|
fap_private_libs=[
|
||||||
Lib(
|
Lib(
|
||||||
name="magic",
|
name="magic",
|
||||||
|
|||||||
175
applications/external/nfc_magic/lib/magic/classic_gen1.c
vendored
Normal file
@@ -0,0 +1,175 @@
|
|||||||
|
#include "classic_gen1.h"
|
||||||
|
|
||||||
|
#include <furi_hal_nfc.h>
|
||||||
|
|
||||||
|
#define TAG "Magic"
|
||||||
|
|
||||||
|
#define MAGIC_CMD_WUPA (0x40)
|
||||||
|
#define MAGIC_CMD_WIPE (0x41)
|
||||||
|
#define MAGIC_CMD_ACCESS (0x43)
|
||||||
|
|
||||||
|
#define MAGIC_MIFARE_READ_CMD (0x30)
|
||||||
|
#define MAGIC_MIFARE_WRITE_CMD (0xA0)
|
||||||
|
|
||||||
|
#define MAGIC_ACK (0x0A)
|
||||||
|
|
||||||
|
#define MAGIC_BUFFER_SIZE (32)
|
||||||
|
|
||||||
|
bool magic_gen1_wupa() {
|
||||||
|
bool magic_activated = false;
|
||||||
|
uint8_t tx_data[MAGIC_BUFFER_SIZE] = {};
|
||||||
|
uint8_t rx_data[MAGIC_BUFFER_SIZE] = {};
|
||||||
|
uint16_t rx_len = 0;
|
||||||
|
FuriHalNfcReturn ret = 0;
|
||||||
|
|
||||||
|
do {
|
||||||
|
// Start communication
|
||||||
|
tx_data[0] = MAGIC_CMD_WUPA;
|
||||||
|
ret = furi_hal_nfc_ll_txrx_bits(
|
||||||
|
tx_data,
|
||||||
|
7,
|
||||||
|
rx_data,
|
||||||
|
sizeof(rx_data),
|
||||||
|
&rx_len,
|
||||||
|
FURI_HAL_NFC_LL_TXRX_FLAGS_CRC_TX_MANUAL | FURI_HAL_NFC_LL_TXRX_FLAGS_AGC_ON |
|
||||||
|
FURI_HAL_NFC_LL_TXRX_FLAGS_CRC_RX_KEEP,
|
||||||
|
furi_hal_nfc_ll_ms2fc(20));
|
||||||
|
if(ret != FuriHalNfcReturnIncompleteByte) break;
|
||||||
|
if(rx_len != 4) break;
|
||||||
|
if(rx_data[0] != MAGIC_ACK) break;
|
||||||
|
magic_activated = true;
|
||||||
|
} while(false);
|
||||||
|
|
||||||
|
return magic_activated;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool magic_gen1_data_access_cmd() {
|
||||||
|
bool write_cmd_success = false;
|
||||||
|
uint8_t tx_data[MAGIC_BUFFER_SIZE] = {};
|
||||||
|
uint8_t rx_data[MAGIC_BUFFER_SIZE] = {};
|
||||||
|
uint16_t rx_len = 0;
|
||||||
|
FuriHalNfcReturn ret = 0;
|
||||||
|
|
||||||
|
do {
|
||||||
|
tx_data[0] = MAGIC_CMD_ACCESS;
|
||||||
|
ret = furi_hal_nfc_ll_txrx_bits(
|
||||||
|
tx_data,
|
||||||
|
8,
|
||||||
|
rx_data,
|
||||||
|
sizeof(rx_data),
|
||||||
|
&rx_len,
|
||||||
|
FURI_HAL_NFC_LL_TXRX_FLAGS_CRC_TX_MANUAL | FURI_HAL_NFC_LL_TXRX_FLAGS_AGC_ON |
|
||||||
|
FURI_HAL_NFC_LL_TXRX_FLAGS_CRC_RX_KEEP,
|
||||||
|
furi_hal_nfc_ll_ms2fc(20));
|
||||||
|
if(ret != FuriHalNfcReturnIncompleteByte) break;
|
||||||
|
if(rx_len != 4) break;
|
||||||
|
if(rx_data[0] != MAGIC_ACK) break;
|
||||||
|
|
||||||
|
write_cmd_success = true;
|
||||||
|
} while(false);
|
||||||
|
|
||||||
|
return write_cmd_success;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool magic_gen1_read_block(uint8_t block_num, MfClassicBlock* data) {
|
||||||
|
furi_assert(data);
|
||||||
|
|
||||||
|
bool read_success = false;
|
||||||
|
|
||||||
|
uint8_t tx_data[MAGIC_BUFFER_SIZE] = {};
|
||||||
|
uint8_t rx_data[MAGIC_BUFFER_SIZE] = {};
|
||||||
|
uint16_t rx_len = 0;
|
||||||
|
FuriHalNfcReturn ret = 0;
|
||||||
|
|
||||||
|
do {
|
||||||
|
tx_data[0] = MAGIC_MIFARE_READ_CMD;
|
||||||
|
tx_data[1] = block_num;
|
||||||
|
ret = furi_hal_nfc_ll_txrx_bits(
|
||||||
|
tx_data,
|
||||||
|
2 * 8,
|
||||||
|
rx_data,
|
||||||
|
sizeof(rx_data),
|
||||||
|
&rx_len,
|
||||||
|
FURI_HAL_NFC_LL_TXRX_FLAGS_AGC_ON,
|
||||||
|
furi_hal_nfc_ll_ms2fc(20));
|
||||||
|
|
||||||
|
if(ret != FuriHalNfcReturnOk) break;
|
||||||
|
if(rx_len != 16 * 8) break;
|
||||||
|
memcpy(data->value, rx_data, sizeof(data->value));
|
||||||
|
read_success = true;
|
||||||
|
} while(false);
|
||||||
|
|
||||||
|
return read_success;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool magic_gen1_write_blk(uint8_t block_num, MfClassicBlock* data) {
|
||||||
|
furi_assert(data);
|
||||||
|
|
||||||
|
bool write_success = false;
|
||||||
|
uint8_t tx_data[MAGIC_BUFFER_SIZE] = {};
|
||||||
|
uint8_t rx_data[MAGIC_BUFFER_SIZE] = {};
|
||||||
|
uint16_t rx_len = 0;
|
||||||
|
FuriHalNfcReturn ret = 0;
|
||||||
|
|
||||||
|
do {
|
||||||
|
tx_data[0] = MAGIC_MIFARE_WRITE_CMD;
|
||||||
|
tx_data[1] = block_num;
|
||||||
|
ret = furi_hal_nfc_ll_txrx_bits(
|
||||||
|
tx_data,
|
||||||
|
2 * 8,
|
||||||
|
rx_data,
|
||||||
|
sizeof(rx_data),
|
||||||
|
&rx_len,
|
||||||
|
FURI_HAL_NFC_LL_TXRX_FLAGS_AGC_ON | FURI_HAL_NFC_LL_TXRX_FLAGS_CRC_RX_KEEP,
|
||||||
|
furi_hal_nfc_ll_ms2fc(20));
|
||||||
|
if(ret != FuriHalNfcReturnIncompleteByte) break;
|
||||||
|
if(rx_len != 4) break;
|
||||||
|
if(rx_data[0] != MAGIC_ACK) break;
|
||||||
|
|
||||||
|
memcpy(tx_data, data->value, sizeof(data->value));
|
||||||
|
ret = furi_hal_nfc_ll_txrx_bits(
|
||||||
|
tx_data,
|
||||||
|
16 * 8,
|
||||||
|
rx_data,
|
||||||
|
sizeof(rx_data),
|
||||||
|
&rx_len,
|
||||||
|
FURI_HAL_NFC_LL_TXRX_FLAGS_AGC_ON | FURI_HAL_NFC_LL_TXRX_FLAGS_CRC_RX_KEEP,
|
||||||
|
furi_hal_nfc_ll_ms2fc(20));
|
||||||
|
if(ret != FuriHalNfcReturnIncompleteByte) break;
|
||||||
|
if(rx_len != 4) break;
|
||||||
|
if(rx_data[0] != MAGIC_ACK) break;
|
||||||
|
|
||||||
|
write_success = true;
|
||||||
|
} while(false);
|
||||||
|
|
||||||
|
return write_success;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool magic_gen1_wipe() {
|
||||||
|
bool wipe_success = false;
|
||||||
|
uint8_t tx_data[MAGIC_BUFFER_SIZE] = {};
|
||||||
|
uint8_t rx_data[MAGIC_BUFFER_SIZE] = {};
|
||||||
|
uint16_t rx_len = 0;
|
||||||
|
FuriHalNfcReturn ret = 0;
|
||||||
|
|
||||||
|
do {
|
||||||
|
tx_data[0] = MAGIC_CMD_WIPE;
|
||||||
|
ret = furi_hal_nfc_ll_txrx_bits(
|
||||||
|
tx_data,
|
||||||
|
8,
|
||||||
|
rx_data,
|
||||||
|
sizeof(rx_data),
|
||||||
|
&rx_len,
|
||||||
|
FURI_HAL_NFC_LL_TXRX_FLAGS_CRC_TX_MANUAL | FURI_HAL_NFC_LL_TXRX_FLAGS_AGC_ON |
|
||||||
|
FURI_HAL_NFC_LL_TXRX_FLAGS_CRC_RX_KEEP,
|
||||||
|
furi_hal_nfc_ll_ms2fc(2000));
|
||||||
|
|
||||||
|
if(ret != FuriHalNfcReturnIncompleteByte) break;
|
||||||
|
if(rx_len != 4) break;
|
||||||
|
if(rx_data[0] != MAGIC_ACK) break;
|
||||||
|
|
||||||
|
wipe_success = true;
|
||||||
|
} while(false);
|
||||||
|
|
||||||
|
return wipe_success;
|
||||||
|
}
|
||||||
13
applications/external/nfc_magic/lib/magic/classic_gen1.h
vendored
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <lib/nfc/protocols/mifare_classic.h>
|
||||||
|
|
||||||
|
bool magic_gen1_wupa();
|
||||||
|
|
||||||
|
bool magic_gen1_read_block(uint8_t block_num, MfClassicBlock* data);
|
||||||
|
|
||||||
|
bool magic_gen1_data_access_cmd();
|
||||||
|
|
||||||
|
bool magic_gen1_write_blk(uint8_t block_num, MfClassicBlock* data);
|
||||||
|
|
||||||
|
bool magic_gen1_wipe();
|
||||||
33
applications/external/nfc_magic/lib/magic/common.c
vendored
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
#include "common.h"
|
||||||
|
|
||||||
|
#include <furi_hal_nfc.h>
|
||||||
|
|
||||||
|
#define REQA (0x26)
|
||||||
|
#define CL1_PREFIX (0x93)
|
||||||
|
#define SELECT (0x70)
|
||||||
|
|
||||||
|
#define MAGIC_BUFFER_SIZE (32)
|
||||||
|
|
||||||
|
bool magic_activate() {
|
||||||
|
FuriHalNfcReturn ret = 0;
|
||||||
|
|
||||||
|
// Setup nfc poller
|
||||||
|
furi_hal_nfc_exit_sleep();
|
||||||
|
furi_hal_nfc_ll_txrx_on();
|
||||||
|
furi_hal_nfc_ll_poll();
|
||||||
|
ret = furi_hal_nfc_ll_set_mode(
|
||||||
|
FuriHalNfcModePollNfca, FuriHalNfcBitrate106, FuriHalNfcBitrate106);
|
||||||
|
if(ret != FuriHalNfcReturnOk) return false;
|
||||||
|
|
||||||
|
furi_hal_nfc_ll_set_fdt_listen(FURI_HAL_NFC_LL_FDT_LISTEN_NFCA_POLLER);
|
||||||
|
furi_hal_nfc_ll_set_fdt_poll(FURI_HAL_NFC_LL_FDT_POLL_NFCA_POLLER);
|
||||||
|
furi_hal_nfc_ll_set_error_handling(FuriHalNfcErrorHandlingNfc);
|
||||||
|
furi_hal_nfc_ll_set_guard_time(FURI_HAL_NFC_LL_GT_NFCA);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void magic_deactivate() {
|
||||||
|
furi_hal_nfc_ll_txrx_off();
|
||||||
|
furi_hal_nfc_sleep();
|
||||||
|
}
|
||||||
19
applications/external/nfc_magic/lib/magic/common.h
vendored
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
MagicTypeClassicGen1,
|
||||||
|
MagicTypeClassicDirectWrite,
|
||||||
|
MagicTypeClassicAPDU,
|
||||||
|
MagicTypeUltralightGen1,
|
||||||
|
MagicTypeUltralightDirectWrite,
|
||||||
|
MagicTypeUltralightC_Gen1,
|
||||||
|
MagicTypeUltralightC_DirectWrite,
|
||||||
|
MagicTypeGen4,
|
||||||
|
} MagicType;
|
||||||
|
|
||||||
|
bool magic_activate();
|
||||||
|
|
||||||
|
void magic_deactivate();
|
||||||
199
applications/external/nfc_magic/lib/magic/gen4.c
vendored
Normal file
@@ -0,0 +1,199 @@
|
|||||||
|
#include "gen4.h"
|
||||||
|
|
||||||
|
#include <furi_hal_nfc.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#define TAG "Magic"
|
||||||
|
|
||||||
|
#define MAGIC_CMD_PREFIX (0xCF)
|
||||||
|
|
||||||
|
#define MAGIC_CMD_GET_CFG (0xC6)
|
||||||
|
#define MAGIC_CMD_WRITE (0xCD)
|
||||||
|
#define MAGIC_CMD_READ (0xCE)
|
||||||
|
#define MAGIC_CMD_SET_CFG (0xF0)
|
||||||
|
#define MAGIC_CMD_FUSE_CFG (0xF1)
|
||||||
|
#define MAGIC_CMD_SET_PWD (0xFE)
|
||||||
|
|
||||||
|
#define MAGIC_BUFFER_SIZE (40)
|
||||||
|
|
||||||
|
const uint8_t MAGIC_DEFAULT_CONFIG[] = {
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x09, 0x78, 0x00, 0x91, 0x02, 0xDA, 0xBC, 0x19, 0x10, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x04, 0x00, 0x08, 0x00
|
||||||
|
};
|
||||||
|
|
||||||
|
const uint8_t MAGIC_DEFAULT_BLOCK0[] = {
|
||||||
|
0x00, 0x01, 0x02, 0x03, 0x04, 0x04, 0x08, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||||
|
};
|
||||||
|
|
||||||
|
const uint8_t MAGIC_EMPTY_BLOCK[16] = { 0 };
|
||||||
|
|
||||||
|
const uint8_t MAGIC_DEFAULT_SECTOR_TRAILER[] = {
|
||||||
|
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x07, 0x80, 0x69, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
|
||||||
|
};
|
||||||
|
|
||||||
|
static bool magic_gen4_is_block_num_trailer(uint8_t n) {
|
||||||
|
n++;
|
||||||
|
if (n < 32 * 4) {
|
||||||
|
return (n % 4 == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (n % 16 == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool magic_gen4_get_cfg(uint32_t pwd, uint8_t* config) {
|
||||||
|
bool is_valid_config_len = false;
|
||||||
|
uint8_t tx_data[MAGIC_BUFFER_SIZE] = {};
|
||||||
|
uint8_t rx_data[MAGIC_BUFFER_SIZE] = {};
|
||||||
|
uint16_t rx_len = 0;
|
||||||
|
FuriHalNfcReturn ret = 0;
|
||||||
|
|
||||||
|
do {
|
||||||
|
// Start communication
|
||||||
|
tx_data[0] = MAGIC_CMD_PREFIX;
|
||||||
|
tx_data[1] = (uint8_t)(pwd >> 24);
|
||||||
|
tx_data[2] = (uint8_t)(pwd >> 16);
|
||||||
|
tx_data[3] = (uint8_t)(pwd >> 8);
|
||||||
|
tx_data[4] = (uint8_t)pwd;
|
||||||
|
tx_data[5] = MAGIC_CMD_GET_CFG;
|
||||||
|
ret = furi_hal_nfc_ll_txrx(
|
||||||
|
tx_data,
|
||||||
|
6,
|
||||||
|
rx_data,
|
||||||
|
sizeof(rx_data),
|
||||||
|
&rx_len,
|
||||||
|
FURI_HAL_NFC_TXRX_DEFAULT,
|
||||||
|
furi_hal_nfc_ll_ms2fc(20));
|
||||||
|
if(ret != FuriHalNfcReturnOk) break;
|
||||||
|
if(rx_len != 30 && rx_len != 32) break;
|
||||||
|
memcpy(config, rx_data, rx_len);
|
||||||
|
is_valid_config_len = true;
|
||||||
|
} while(false);
|
||||||
|
|
||||||
|
return is_valid_config_len;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool magic_gen4_set_cfg(uint32_t pwd, const uint8_t* config, uint8_t config_length, bool fuse) {
|
||||||
|
bool write_success = false;
|
||||||
|
uint8_t tx_data[MAGIC_BUFFER_SIZE] = {};
|
||||||
|
uint8_t rx_data[MAGIC_BUFFER_SIZE] = {};
|
||||||
|
uint16_t rx_len = 0;
|
||||||
|
FuriHalNfcReturn ret = 0;
|
||||||
|
|
||||||
|
do {
|
||||||
|
// Start communication
|
||||||
|
tx_data[0] = MAGIC_CMD_PREFIX;
|
||||||
|
tx_data[1] = (uint8_t)(pwd >> 24);
|
||||||
|
tx_data[2] = (uint8_t)(pwd >> 16);
|
||||||
|
tx_data[3] = (uint8_t)(pwd >> 8);
|
||||||
|
tx_data[4] = (uint8_t)pwd;
|
||||||
|
tx_data[5] = fuse ? MAGIC_CMD_FUSE_CFG : MAGIC_CMD_SET_CFG;
|
||||||
|
memcpy(tx_data + 6, config, config_length);
|
||||||
|
ret = furi_hal_nfc_ll_txrx(
|
||||||
|
tx_data,
|
||||||
|
6 + config_length,
|
||||||
|
rx_data,
|
||||||
|
sizeof(rx_data),
|
||||||
|
&rx_len,
|
||||||
|
FURI_HAL_NFC_TXRX_DEFAULT,
|
||||||
|
furi_hal_nfc_ll_ms2fc(20));
|
||||||
|
if(ret != FuriHalNfcReturnOk) break;
|
||||||
|
if(rx_len != 2) break;
|
||||||
|
write_success = true;
|
||||||
|
} while(false);
|
||||||
|
|
||||||
|
return write_success;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool magic_gen4_set_pwd(uint32_t old_pwd, uint32_t new_pwd) {
|
||||||
|
bool change_success = false;
|
||||||
|
uint8_t tx_data[MAGIC_BUFFER_SIZE] = {};
|
||||||
|
uint8_t rx_data[MAGIC_BUFFER_SIZE] = {};
|
||||||
|
uint16_t rx_len = 0;
|
||||||
|
FuriHalNfcReturn ret = 0;
|
||||||
|
|
||||||
|
do {
|
||||||
|
// Start communication
|
||||||
|
tx_data[0] = MAGIC_CMD_PREFIX;
|
||||||
|
tx_data[1] = (uint8_t)(old_pwd >> 24);
|
||||||
|
tx_data[2] = (uint8_t)(old_pwd >> 16);
|
||||||
|
tx_data[3] = (uint8_t)(old_pwd >> 8);
|
||||||
|
tx_data[4] = (uint8_t)old_pwd;
|
||||||
|
tx_data[5] = MAGIC_CMD_SET_PWD;
|
||||||
|
tx_data[6] = (uint8_t)(new_pwd >> 24);
|
||||||
|
tx_data[7] = (uint8_t)(new_pwd >> 16);
|
||||||
|
tx_data[8] = (uint8_t)(new_pwd >> 8);
|
||||||
|
tx_data[9] = (uint8_t)new_pwd;
|
||||||
|
ret = furi_hal_nfc_ll_txrx(
|
||||||
|
tx_data,
|
||||||
|
10,
|
||||||
|
rx_data,
|
||||||
|
sizeof(rx_data),
|
||||||
|
&rx_len,
|
||||||
|
FURI_HAL_NFC_TXRX_DEFAULT,
|
||||||
|
furi_hal_nfc_ll_ms2fc(20));
|
||||||
|
FURI_LOG_I(TAG, "ret %d, len %d", ret, rx_len);
|
||||||
|
if(ret != FuriHalNfcReturnOk) break;
|
||||||
|
if(rx_len != 2) break;
|
||||||
|
change_success = true;
|
||||||
|
} while(false);
|
||||||
|
|
||||||
|
return change_success;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool magic_gen4_write_blk(uint32_t pwd, uint8_t block_num, const uint8_t* data) {
|
||||||
|
bool write_success = false;
|
||||||
|
uint8_t tx_data[MAGIC_BUFFER_SIZE] = {};
|
||||||
|
uint8_t rx_data[MAGIC_BUFFER_SIZE] = {};
|
||||||
|
uint16_t rx_len = 0;
|
||||||
|
FuriHalNfcReturn ret = 0;
|
||||||
|
|
||||||
|
do {
|
||||||
|
// Start communication
|
||||||
|
tx_data[0] = MAGIC_CMD_PREFIX;
|
||||||
|
tx_data[1] = (uint8_t)(pwd >> 24);
|
||||||
|
tx_data[2] = (uint8_t)(pwd >> 16);
|
||||||
|
tx_data[3] = (uint8_t)(pwd >> 8);
|
||||||
|
tx_data[4] = (uint8_t)pwd;
|
||||||
|
tx_data[5] = MAGIC_CMD_WRITE;
|
||||||
|
tx_data[6] = block_num;
|
||||||
|
memcpy(tx_data + 7, data, 16);
|
||||||
|
ret = furi_hal_nfc_ll_txrx(
|
||||||
|
tx_data,
|
||||||
|
23,
|
||||||
|
rx_data,
|
||||||
|
sizeof(rx_data),
|
||||||
|
&rx_len,
|
||||||
|
FURI_HAL_NFC_TXRX_DEFAULT,
|
||||||
|
furi_hal_nfc_ll_ms2fc(200));
|
||||||
|
if(ret != FuriHalNfcReturnOk) break;
|
||||||
|
if(rx_len != 2) break;
|
||||||
|
write_success = true;
|
||||||
|
} while(false);
|
||||||
|
|
||||||
|
return write_success;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool magic_gen4_wipe(uint32_t pwd) {
|
||||||
|
if(!magic_gen4_set_cfg(pwd, MAGIC_DEFAULT_CONFIG, sizeof(MAGIC_DEFAULT_CONFIG), false)) {
|
||||||
|
FURI_LOG_E(TAG, "Set config failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(!magic_gen4_write_blk(pwd, 0, MAGIC_DEFAULT_BLOCK0)) {
|
||||||
|
FURI_LOG_E(TAG, "Block 0 write failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for(size_t i = 1; i < 64; i++) {
|
||||||
|
const uint8_t* block = magic_gen4_is_block_num_trailer(i) ? MAGIC_DEFAULT_SECTOR_TRAILER : MAGIC_EMPTY_BLOCK;
|
||||||
|
if(!magic_gen4_write_blk(pwd, i, block)) {
|
||||||
|
FURI_LOG_E(TAG, "Block %d write failed", i);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(size_t i = 65; i < 256; i++) {
|
||||||
|
if(!magic_gen4_write_blk(pwd, i, MAGIC_EMPTY_BLOCK)) {
|
||||||
|
FURI_LOG_E(TAG, "Block %d write failed", i);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
48
applications/external/nfc_magic/lib/magic/gen4.h
vendored
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <lib/nfc/protocols/mifare_classic.h>
|
||||||
|
|
||||||
|
#define MAGIC_GEN4_DEFAULT_PWD 0x00000000
|
||||||
|
#define MAGIC_GEN4_CONFIG_LEN 32
|
||||||
|
|
||||||
|
#define NFCID1_SINGLE_SIZE 4
|
||||||
|
#define NFCID1_DOUBLE_SIZE 7
|
||||||
|
#define NFCID1_TRIPLE_SIZE 10
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
MagicGen4UIDLengthSingle = 0x00,
|
||||||
|
MagicGen4UIDLengthDouble = 0x01,
|
||||||
|
MagicGen4UIDLengthTriple = 0x02
|
||||||
|
} MagicGen4UIDLength;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
MagicGen4UltralightModeUL_EV1 = 0x00,
|
||||||
|
MagicGen4UltralightModeNTAG = 0x01,
|
||||||
|
MagicGen4UltralightModeUL_C = 0x02,
|
||||||
|
MagicGen4UltralightModeUL = 0x03
|
||||||
|
} MagicGen4UltralightMode;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
// for writing original (shadow) data
|
||||||
|
MagicGen4ShadowModePreWrite = 0x00,
|
||||||
|
// written data can be read once before restored to original
|
||||||
|
MagicGen4ShadowModeRestore = 0x01,
|
||||||
|
// written data is discarded
|
||||||
|
MagicGen4ShadowModeIgnore = 0x02,
|
||||||
|
// apparently for UL?
|
||||||
|
MagicGen4ShadowModeHighSpeedIgnore = 0x03
|
||||||
|
} MagicGen4ShadowMode;
|
||||||
|
|
||||||
|
bool magic_gen4_get_cfg(uint32_t pwd, uint8_t* config);
|
||||||
|
|
||||||
|
bool magic_gen4_set_cfg(uint32_t pwd, const uint8_t* config, uint8_t config_length, bool fuse);
|
||||||
|
|
||||||
|
bool magic_gen4_set_pwd(uint32_t old_pwd, uint32_t new_pwd);
|
||||||
|
|
||||||
|
bool magic_gen4_read_blk(uint32_t pwd, uint8_t block_num, uint8_t* data);
|
||||||
|
|
||||||
|
bool magic_gen4_write_blk(uint32_t pwd, uint8_t block_num, const uint8_t* data);
|
||||||
|
|
||||||
|
bool magic_gen4_wipe(uint32_t pwd);
|
||||||
|
|
||||||
|
void magic_gen4_deactivate();
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "magic.h"
|
#include "classic_gen1.h"
|
||||||
|
|
||||||
#include <furi_hal_nfc.h>
|
#include <furi_hal_nfc.h>
|
||||||
|
|
||||||
@@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
#define MAGIC_BUFFER_SIZE (32)
|
#define MAGIC_BUFFER_SIZE (32)
|
||||||
|
|
||||||
bool magic_wupa() {
|
bool magic_gen1_wupa() {
|
||||||
bool magic_activated = false;
|
bool magic_activated = false;
|
||||||
uint8_t tx_data[MAGIC_BUFFER_SIZE] = {};
|
uint8_t tx_data[MAGIC_BUFFER_SIZE] = {};
|
||||||
uint8_t rx_data[MAGIC_BUFFER_SIZE] = {};
|
uint8_t rx_data[MAGIC_BUFFER_SIZE] = {};
|
||||||
@@ -23,19 +23,6 @@ bool magic_wupa() {
|
|||||||
FuriHalNfcReturn ret = 0;
|
FuriHalNfcReturn ret = 0;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
// Setup nfc poller
|
|
||||||
furi_hal_nfc_exit_sleep();
|
|
||||||
furi_hal_nfc_ll_txrx_on();
|
|
||||||
furi_hal_nfc_ll_poll();
|
|
||||||
ret = furi_hal_nfc_ll_set_mode(
|
|
||||||
FuriHalNfcModePollNfca, FuriHalNfcBitrate106, FuriHalNfcBitrate106);
|
|
||||||
if(ret != FuriHalNfcReturnOk) break;
|
|
||||||
|
|
||||||
furi_hal_nfc_ll_set_fdt_listen(FURI_HAL_NFC_LL_FDT_LISTEN_NFCA_POLLER);
|
|
||||||
furi_hal_nfc_ll_set_fdt_poll(FURI_HAL_NFC_LL_FDT_POLL_NFCA_POLLER);
|
|
||||||
furi_hal_nfc_ll_set_error_handling(FuriHalNfcErrorHandlingNfc);
|
|
||||||
furi_hal_nfc_ll_set_guard_time(FURI_HAL_NFC_LL_GT_NFCA);
|
|
||||||
|
|
||||||
// Start communication
|
// Start communication
|
||||||
tx_data[0] = MAGIC_CMD_WUPA;
|
tx_data[0] = MAGIC_CMD_WUPA;
|
||||||
ret = furi_hal_nfc_ll_txrx_bits(
|
ret = furi_hal_nfc_ll_txrx_bits(
|
||||||
@@ -53,15 +40,10 @@ bool magic_wupa() {
|
|||||||
magic_activated = true;
|
magic_activated = true;
|
||||||
} while(false);
|
} while(false);
|
||||||
|
|
||||||
if(!magic_activated) {
|
|
||||||
furi_hal_nfc_ll_txrx_off();
|
|
||||||
furi_hal_nfc_start_sleep();
|
|
||||||
}
|
|
||||||
|
|
||||||
return magic_activated;
|
return magic_activated;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool magic_data_access_cmd() {
|
bool magic_gen1_data_access_cmd() {
|
||||||
bool write_cmd_success = false;
|
bool write_cmd_success = false;
|
||||||
uint8_t tx_data[MAGIC_BUFFER_SIZE] = {};
|
uint8_t tx_data[MAGIC_BUFFER_SIZE] = {};
|
||||||
uint8_t rx_data[MAGIC_BUFFER_SIZE] = {};
|
uint8_t rx_data[MAGIC_BUFFER_SIZE] = {};
|
||||||
@@ -86,15 +68,10 @@ bool magic_data_access_cmd() {
|
|||||||
write_cmd_success = true;
|
write_cmd_success = true;
|
||||||
} while(false);
|
} while(false);
|
||||||
|
|
||||||
if(!write_cmd_success) {
|
|
||||||
furi_hal_nfc_ll_txrx_off();
|
|
||||||
furi_hal_nfc_start_sleep();
|
|
||||||
}
|
|
||||||
|
|
||||||
return write_cmd_success;
|
return write_cmd_success;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool magic_read_block(uint8_t block_num, MfClassicBlock* data) {
|
bool magic_gen1_read_block(uint8_t block_num, MfClassicBlock* data) {
|
||||||
furi_assert(data);
|
furi_assert(data);
|
||||||
|
|
||||||
bool read_success = false;
|
bool read_success = false;
|
||||||
@@ -122,15 +99,10 @@ bool magic_read_block(uint8_t block_num, MfClassicBlock* data) {
|
|||||||
read_success = true;
|
read_success = true;
|
||||||
} while(false);
|
} while(false);
|
||||||
|
|
||||||
if(!read_success) {
|
|
||||||
furi_hal_nfc_ll_txrx_off();
|
|
||||||
furi_hal_nfc_start_sleep();
|
|
||||||
}
|
|
||||||
|
|
||||||
return read_success;
|
return read_success;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool magic_write_blk(uint8_t block_num, MfClassicBlock* data) {
|
bool magic_gen1_write_blk(uint8_t block_num, MfClassicBlock* data) {
|
||||||
furi_assert(data);
|
furi_assert(data);
|
||||||
|
|
||||||
bool write_success = false;
|
bool write_success = false;
|
||||||
@@ -170,15 +142,10 @@ bool magic_write_blk(uint8_t block_num, MfClassicBlock* data) {
|
|||||||
write_success = true;
|
write_success = true;
|
||||||
} while(false);
|
} while(false);
|
||||||
|
|
||||||
if(!write_success) {
|
|
||||||
furi_hal_nfc_ll_txrx_off();
|
|
||||||
furi_hal_nfc_start_sleep();
|
|
||||||
}
|
|
||||||
|
|
||||||
return write_success;
|
return write_success;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool magic_wipe() {
|
bool magic_gen1_wipe() {
|
||||||
bool wipe_success = false;
|
bool wipe_success = false;
|
||||||
uint8_t tx_data[MAGIC_BUFFER_SIZE] = {};
|
uint8_t tx_data[MAGIC_BUFFER_SIZE] = {};
|
||||||
uint8_t rx_data[MAGIC_BUFFER_SIZE] = {};
|
uint8_t rx_data[MAGIC_BUFFER_SIZE] = {};
|
||||||
@@ -205,9 +172,4 @@ bool magic_wipe() {
|
|||||||
} while(false);
|
} while(false);
|
||||||
|
|
||||||
return wipe_success;
|
return wipe_success;
|
||||||
}
|
}
|
||||||
|
|
||||||
void magic_deactivate() {
|
|
||||||
furi_hal_nfc_ll_txrx_off();
|
|
||||||
furi_hal_nfc_sleep();
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <lib/nfc/protocols/mifare_classic.h>
|
|
||||||
|
|
||||||
bool magic_wupa();
|
|
||||||
|
|
||||||
bool magic_read_block(uint8_t block_num, MfClassicBlock* data);
|
|
||||||
|
|
||||||
bool magic_data_access_cmd();
|
|
||||||
|
|
||||||
bool magic_write_blk(uint8_t block_num, MfClassicBlock* data);
|
|
||||||
|
|
||||||
bool magic_wipe();
|
|
||||||
|
|
||||||
void magic_deactivate();
|
|
||||||
23
applications/external/nfc_magic/lib/magic/types.c
vendored
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
#include "types.h"
|
||||||
|
|
||||||
|
const char* nfc_magic_type(MagicType type) {
|
||||||
|
if(type == MagicTypeClassicGen1) {
|
||||||
|
return "Classic Gen 1A/B";
|
||||||
|
} else if(type == MagicTypeClassicDirectWrite) {
|
||||||
|
return "Classic DirectWrite";
|
||||||
|
} else if(type == MagicTypeClassicAPDU) {
|
||||||
|
return "Classic APDU";
|
||||||
|
} else if(type == MagicTypeUltralightGen1) {
|
||||||
|
return "Ultralight Gen 1";
|
||||||
|
} else if(type == MagicTypeUltralightDirectWrite) {
|
||||||
|
return "Ultralight DirectWrite";
|
||||||
|
} else if(type == MagicTypeUltralightC_Gen1) {
|
||||||
|
return "Ultralight-C Gen 1";
|
||||||
|
} else if(type == MagicTypeUltralightC_DirectWrite) {
|
||||||
|
return "Ultralight-C DirectWrite";
|
||||||
|
} else if(type == MagicTypeGen4) {
|
||||||
|
return "Gen 4 GTU";
|
||||||
|
} else {
|
||||||
|
return "Unknown";
|
||||||
|
}
|
||||||
|
}
|
||||||
5
applications/external/nfc_magic/lib/magic/types.h
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
|
const char* nfc_magic_type(MagicType type);
|
||||||
22
applications/external/nfc_magic/nfc_magic.c
vendored
@@ -48,8 +48,9 @@ NfcMagic* nfc_magic_alloc() {
|
|||||||
nfc_magic->view_dispatcher, nfc_magic_tick_event_callback, 100);
|
nfc_magic->view_dispatcher, nfc_magic_tick_event_callback, 100);
|
||||||
|
|
||||||
// Nfc device
|
// Nfc device
|
||||||
nfc_magic->nfc_dev = nfc_device_alloc();
|
nfc_magic->dev = malloc(sizeof(NfcMagicDevice));
|
||||||
furi_string_set(nfc_magic->nfc_dev->folder, NFC_APP_FOLDER);
|
nfc_magic->source_dev = nfc_device_alloc();
|
||||||
|
furi_string_set(nfc_magic->source_dev->folder, NFC_APP_FOLDER);
|
||||||
|
|
||||||
// Open GUI record
|
// Open GUI record
|
||||||
nfc_magic->gui = furi_record_open(RECORD_GUI);
|
nfc_magic->gui = furi_record_open(RECORD_GUI);
|
||||||
@@ -81,6 +82,13 @@ NfcMagic* nfc_magic_alloc() {
|
|||||||
NfcMagicViewTextInput,
|
NfcMagicViewTextInput,
|
||||||
text_input_get_view(nfc_magic->text_input));
|
text_input_get_view(nfc_magic->text_input));
|
||||||
|
|
||||||
|
// Byte Input
|
||||||
|
nfc_magic->byte_input = byte_input_alloc();
|
||||||
|
view_dispatcher_add_view(
|
||||||
|
nfc_magic->view_dispatcher,
|
||||||
|
NfcMagicViewByteInput,
|
||||||
|
byte_input_get_view(nfc_magic->byte_input));
|
||||||
|
|
||||||
// Custom Widget
|
// Custom Widget
|
||||||
nfc_magic->widget = widget_alloc();
|
nfc_magic->widget = widget_alloc();
|
||||||
view_dispatcher_add_view(
|
view_dispatcher_add_view(
|
||||||
@@ -93,7 +101,8 @@ void nfc_magic_free(NfcMagic* nfc_magic) {
|
|||||||
furi_assert(nfc_magic);
|
furi_assert(nfc_magic);
|
||||||
|
|
||||||
// Nfc device
|
// Nfc device
|
||||||
nfc_device_free(nfc_magic->nfc_dev);
|
free(nfc_magic->dev);
|
||||||
|
nfc_device_free(nfc_magic->source_dev);
|
||||||
|
|
||||||
// Submenu
|
// Submenu
|
||||||
view_dispatcher_remove_view(nfc_magic->view_dispatcher, NfcMagicViewMenu);
|
view_dispatcher_remove_view(nfc_magic->view_dispatcher, NfcMagicViewMenu);
|
||||||
@@ -107,10 +116,14 @@ void nfc_magic_free(NfcMagic* nfc_magic) {
|
|||||||
view_dispatcher_remove_view(nfc_magic->view_dispatcher, NfcMagicViewLoading);
|
view_dispatcher_remove_view(nfc_magic->view_dispatcher, NfcMagicViewLoading);
|
||||||
loading_free(nfc_magic->loading);
|
loading_free(nfc_magic->loading);
|
||||||
|
|
||||||
// TextInput
|
// Text Input
|
||||||
view_dispatcher_remove_view(nfc_magic->view_dispatcher, NfcMagicViewTextInput);
|
view_dispatcher_remove_view(nfc_magic->view_dispatcher, NfcMagicViewTextInput);
|
||||||
text_input_free(nfc_magic->text_input);
|
text_input_free(nfc_magic->text_input);
|
||||||
|
|
||||||
|
// Byte Input
|
||||||
|
view_dispatcher_remove_view(nfc_magic->view_dispatcher, NfcMagicViewByteInput);
|
||||||
|
byte_input_free(nfc_magic->byte_input);
|
||||||
|
|
||||||
// Custom Widget
|
// Custom Widget
|
||||||
view_dispatcher_remove_view(nfc_magic->view_dispatcher, NfcMagicViewWidget);
|
view_dispatcher_remove_view(nfc_magic->view_dispatcher, NfcMagicViewWidget);
|
||||||
widget_free(nfc_magic->widget);
|
widget_free(nfc_magic->widget);
|
||||||
@@ -164,6 +177,7 @@ int32_t nfc_magic_app(void* p) {
|
|||||||
|
|
||||||
view_dispatcher_run(nfc_magic->view_dispatcher);
|
view_dispatcher_run(nfc_magic->view_dispatcher);
|
||||||
|
|
||||||
|
magic_deactivate();
|
||||||
nfc_magic_free(nfc_magic);
|
nfc_magic_free(nfc_magic);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
2
applications/external/nfc_magic/nfc_magic.h
vendored
@@ -1,3 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
typedef struct NfcMagicDevice NfcMagicDevice;
|
||||||
|
|
||||||
typedef struct NfcMagic NfcMagic;
|
typedef struct NfcMagic NfcMagic;
|
||||||
|
|||||||
20
applications/external/nfc_magic/nfc_magic_i.h
vendored
@@ -3,7 +3,10 @@
|
|||||||
#include "nfc_magic.h"
|
#include "nfc_magic.h"
|
||||||
#include "nfc_magic_worker.h"
|
#include "nfc_magic_worker.h"
|
||||||
|
|
||||||
#include "lib/magic/magic.h"
|
#include "lib/magic/common.h"
|
||||||
|
#include "lib/magic/types.h"
|
||||||
|
#include "lib/magic/classic_gen1.h"
|
||||||
|
#include "lib/magic/gen4.h"
|
||||||
|
|
||||||
#include <furi.h>
|
#include <furi.h>
|
||||||
#include <gui/gui.h>
|
#include <gui/gui.h>
|
||||||
@@ -15,6 +18,7 @@
|
|||||||
#include <gui/modules/popup.h>
|
#include <gui/modules/popup.h>
|
||||||
#include <gui/modules/loading.h>
|
#include <gui/modules/loading.h>
|
||||||
#include <gui/modules/text_input.h>
|
#include <gui/modules/text_input.h>
|
||||||
|
#include <gui/modules/byte_input.h>
|
||||||
#include <gui/modules/widget.h>
|
#include <gui/modules/widget.h>
|
||||||
|
|
||||||
#include <input/input.h>
|
#include <input/input.h>
|
||||||
@@ -39,14 +43,22 @@ enum NfcMagicCustomEvent {
|
|||||||
NfcMagicCustomEventTextInputDone,
|
NfcMagicCustomEventTextInputDone,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct NfcMagicDevice {
|
||||||
|
MagicType type;
|
||||||
|
uint32_t cuid;
|
||||||
|
uint32_t password;
|
||||||
|
};
|
||||||
|
|
||||||
struct NfcMagic {
|
struct NfcMagic {
|
||||||
NfcMagicWorker* worker;
|
NfcMagicWorker* worker;
|
||||||
ViewDispatcher* view_dispatcher;
|
ViewDispatcher* view_dispatcher;
|
||||||
Gui* gui;
|
Gui* gui;
|
||||||
NotificationApp* notifications;
|
NotificationApp* notifications;
|
||||||
SceneManager* scene_manager;
|
SceneManager* scene_manager;
|
||||||
// NfcMagicDevice* dev;
|
struct NfcMagicDevice* dev;
|
||||||
NfcDevice* nfc_dev;
|
NfcDevice* source_dev;
|
||||||
|
|
||||||
|
uint32_t new_password;
|
||||||
|
|
||||||
FuriString* text_box_store;
|
FuriString* text_box_store;
|
||||||
|
|
||||||
@@ -55,6 +67,7 @@ struct NfcMagic {
|
|||||||
Popup* popup;
|
Popup* popup;
|
||||||
Loading* loading;
|
Loading* loading;
|
||||||
TextInput* text_input;
|
TextInput* text_input;
|
||||||
|
ByteInput* byte_input;
|
||||||
Widget* widget;
|
Widget* widget;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -63,6 +76,7 @@ typedef enum {
|
|||||||
NfcMagicViewPopup,
|
NfcMagicViewPopup,
|
||||||
NfcMagicViewLoading,
|
NfcMagicViewLoading,
|
||||||
NfcMagicViewTextInput,
|
NfcMagicViewTextInput,
|
||||||
|
NfcMagicViewByteInput,
|
||||||
NfcMagicViewWidget,
|
NfcMagicViewWidget,
|
||||||
} NfcMagicView;
|
} NfcMagicView;
|
||||||
|
|
||||||
|
|||||||
372
applications/external/nfc_magic/nfc_magic_worker.c
vendored
@@ -1,6 +1,9 @@
|
|||||||
#include "nfc_magic_worker_i.h"
|
#include "nfc_magic_worker_i.h"
|
||||||
|
|
||||||
#include "lib/magic/magic.h"
|
#include "nfc_magic_i.h"
|
||||||
|
#include "lib/magic/common.h"
|
||||||
|
#include "lib/magic/classic_gen1.h"
|
||||||
|
#include "lib/magic/gen4.h"
|
||||||
|
|
||||||
#define TAG "NfcMagicWorker"
|
#define TAG "NfcMagicWorker"
|
||||||
|
|
||||||
@@ -43,10 +46,13 @@ void nfc_magic_worker_stop(NfcMagicWorker* nfc_magic_worker) {
|
|||||||
void nfc_magic_worker_start(
|
void nfc_magic_worker_start(
|
||||||
NfcMagicWorker* nfc_magic_worker,
|
NfcMagicWorker* nfc_magic_worker,
|
||||||
NfcMagicWorkerState state,
|
NfcMagicWorkerState state,
|
||||||
|
NfcMagicDevice* magic_dev,
|
||||||
NfcDeviceData* dev_data,
|
NfcDeviceData* dev_data,
|
||||||
|
uint32_t new_password,
|
||||||
NfcMagicWorkerCallback callback,
|
NfcMagicWorkerCallback callback,
|
||||||
void* context) {
|
void* context) {
|
||||||
furi_assert(nfc_magic_worker);
|
furi_assert(nfc_magic_worker);
|
||||||
|
furi_assert(magic_dev);
|
||||||
furi_assert(dev_data);
|
furi_assert(dev_data);
|
||||||
|
|
||||||
furi_hal_nfc_deinit();
|
furi_hal_nfc_deinit();
|
||||||
@@ -54,7 +60,9 @@ void nfc_magic_worker_start(
|
|||||||
|
|
||||||
nfc_magic_worker->callback = callback;
|
nfc_magic_worker->callback = callback;
|
||||||
nfc_magic_worker->context = context;
|
nfc_magic_worker->context = context;
|
||||||
|
nfc_magic_worker->magic_dev = magic_dev;
|
||||||
nfc_magic_worker->dev_data = dev_data;
|
nfc_magic_worker->dev_data = dev_data;
|
||||||
|
nfc_magic_worker->new_password = new_password;
|
||||||
nfc_magic_worker_change_state(nfc_magic_worker, state);
|
nfc_magic_worker_change_state(nfc_magic_worker, state);
|
||||||
furi_thread_start(nfc_magic_worker->thread);
|
furi_thread_start(nfc_magic_worker->thread);
|
||||||
}
|
}
|
||||||
@@ -66,6 +74,8 @@ int32_t nfc_magic_worker_task(void* context) {
|
|||||||
nfc_magic_worker_check(nfc_magic_worker);
|
nfc_magic_worker_check(nfc_magic_worker);
|
||||||
} else if(nfc_magic_worker->state == NfcMagicWorkerStateWrite) {
|
} else if(nfc_magic_worker->state == NfcMagicWorkerStateWrite) {
|
||||||
nfc_magic_worker_write(nfc_magic_worker);
|
nfc_magic_worker_write(nfc_magic_worker);
|
||||||
|
} else if(nfc_magic_worker->state == NfcMagicWorkerStateRekey) {
|
||||||
|
nfc_magic_worker_rekey(nfc_magic_worker);
|
||||||
} else if(nfc_magic_worker->state == NfcMagicWorkerStateWipe) {
|
} else if(nfc_magic_worker->state == NfcMagicWorkerStateWipe) {
|
||||||
nfc_magic_worker_wipe(nfc_magic_worker);
|
nfc_magic_worker_wipe(nfc_magic_worker);
|
||||||
}
|
}
|
||||||
@@ -77,59 +87,245 @@ int32_t nfc_magic_worker_task(void* context) {
|
|||||||
|
|
||||||
void nfc_magic_worker_write(NfcMagicWorker* nfc_magic_worker) {
|
void nfc_magic_worker_write(NfcMagicWorker* nfc_magic_worker) {
|
||||||
bool card_found_notified = false;
|
bool card_found_notified = false;
|
||||||
|
bool done = false;
|
||||||
FuriHalNfcDevData nfc_data = {};
|
FuriHalNfcDevData nfc_data = {};
|
||||||
MfClassicData* src_data = &nfc_magic_worker->dev_data->mf_classic_data;
|
NfcMagicDevice* magic_dev = nfc_magic_worker->magic_dev;
|
||||||
|
NfcDeviceData* dev_data = nfc_magic_worker->dev_data;
|
||||||
|
NfcProtocol dev_protocol = dev_data->protocol;
|
||||||
|
|
||||||
while(nfc_magic_worker->state == NfcMagicWorkerStateWrite) {
|
while(nfc_magic_worker->state == NfcMagicWorkerStateWrite) {
|
||||||
if(furi_hal_nfc_detect(&nfc_data, 200)) {
|
do {
|
||||||
if(!card_found_notified) {
|
if(furi_hal_nfc_detect(&nfc_data, 200)) {
|
||||||
nfc_magic_worker->callback(
|
if(nfc_data.cuid != magic_dev->cuid) break;
|
||||||
NfcMagicWorkerEventCardDetected, nfc_magic_worker->context);
|
if(!card_found_notified) {
|
||||||
card_found_notified = true;
|
nfc_magic_worker->callback(
|
||||||
}
|
NfcMagicWorkerEventCardDetected, nfc_magic_worker->context);
|
||||||
furi_hal_nfc_sleep();
|
card_found_notified = true;
|
||||||
if(!magic_wupa()) {
|
}
|
||||||
FURI_LOG_E(TAG, "No card response to WUPA (not a magic card)");
|
furi_hal_nfc_sleep();
|
||||||
nfc_magic_worker->callback(
|
|
||||||
NfcMagicWorkerEventWrongCard, nfc_magic_worker->context);
|
magic_activate();
|
||||||
break;
|
if(magic_dev->type == MagicTypeClassicGen1) {
|
||||||
}
|
if(dev_protocol != NfcDeviceProtocolMifareClassic) break;
|
||||||
furi_hal_nfc_sleep();
|
MfClassicData* mfc_data = &dev_data->mf_classic_data;
|
||||||
}
|
|
||||||
if(magic_wupa()) {
|
if(mfc_data->type != MfClassicType1k) break;
|
||||||
if(!magic_data_access_cmd()) {
|
if(!magic_gen1_wupa()) {
|
||||||
FURI_LOG_E(TAG, "No card response to data access command (not a magic card)");
|
FURI_LOG_E(TAG, "Not Magic card");
|
||||||
nfc_magic_worker->callback(
|
nfc_magic_worker->callback(
|
||||||
NfcMagicWorkerEventWrongCard, nfc_magic_worker->context);
|
NfcMagicWorkerEventWrongCard, nfc_magic_worker->context);
|
||||||
break;
|
done = true;
|
||||||
}
|
break;
|
||||||
for(size_t i = 0; i < 64; i++) {
|
}
|
||||||
FURI_LOG_D(TAG, "Writing block %d", i);
|
if(!magic_gen1_data_access_cmd()) {
|
||||||
if(!magic_write_blk(i, &src_data->block[i])) {
|
FURI_LOG_E(TAG, "Not Magic card");
|
||||||
FURI_LOG_E(TAG, "Failed to write %d block", i);
|
nfc_magic_worker->callback(
|
||||||
nfc_magic_worker->callback(NfcMagicWorkerEventFail, nfc_magic_worker->context);
|
NfcMagicWorkerEventWrongCard, nfc_magic_worker->context);
|
||||||
|
done = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
for(size_t i = 0; i < 64; i++) {
|
||||||
|
FURI_LOG_D(TAG, "Writing block %d", i);
|
||||||
|
if(!magic_gen1_write_blk(i, &mfc_data->block[i])) {
|
||||||
|
FURI_LOG_E(TAG, "Failed to write %d block", i);
|
||||||
|
nfc_magic_worker->callback(
|
||||||
|
NfcMagicWorkerEventFail, nfc_magic_worker->context);
|
||||||
|
done = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
nfc_magic_worker->callback(
|
||||||
|
NfcMagicWorkerEventSuccess, nfc_magic_worker->context);
|
||||||
|
done = true;
|
||||||
|
break;
|
||||||
|
} else if(magic_dev->type == MagicTypeGen4) {
|
||||||
|
uint8_t gen4_config[28];
|
||||||
|
uint32_t password = magic_dev->password;
|
||||||
|
|
||||||
|
uint32_t cuid;
|
||||||
|
if(dev_protocol == NfcDeviceProtocolMifareClassic) {
|
||||||
|
gen4_config[0] = 0x00;
|
||||||
|
gen4_config[27] = 0x00;
|
||||||
|
} else if(dev_protocol == NfcDeviceProtocolMifareUl) {
|
||||||
|
MfUltralightData* mf_ul_data = &dev_data->mf_ul_data;
|
||||||
|
gen4_config[0] = 0x01;
|
||||||
|
switch(mf_ul_data->type) {
|
||||||
|
case MfUltralightTypeUL11:
|
||||||
|
case MfUltralightTypeUL21:
|
||||||
|
// UL-C?
|
||||||
|
// UL?
|
||||||
|
default:
|
||||||
|
gen4_config[27] = MagicGen4UltralightModeUL_EV1;
|
||||||
|
break;
|
||||||
|
case MfUltralightTypeNTAG203:
|
||||||
|
case MfUltralightTypeNTAG213:
|
||||||
|
case MfUltralightTypeNTAG215:
|
||||||
|
case MfUltralightTypeNTAG216:
|
||||||
|
case MfUltralightTypeNTAGI2C1K:
|
||||||
|
case MfUltralightTypeNTAGI2C2K:
|
||||||
|
case MfUltralightTypeNTAGI2CPlus1K:
|
||||||
|
case MfUltralightTypeNTAGI2CPlus2K:
|
||||||
|
gen4_config[27] = MagicGen4UltralightModeNTAG;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(dev_data->nfc_data.uid_len == 4) {
|
||||||
|
gen4_config[1] = MagicGen4UIDLengthSingle;
|
||||||
|
} else if(dev_data->nfc_data.uid_len == 7) {
|
||||||
|
gen4_config[1] = MagicGen4UIDLengthDouble;
|
||||||
|
} else {
|
||||||
|
FURI_LOG_E(TAG, "Unexpected UID length %d", dev_data->nfc_data.uid_len);
|
||||||
|
nfc_magic_worker->callback(
|
||||||
|
NfcMagicWorkerEventFail, nfc_magic_worker->context);
|
||||||
|
done = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
gen4_config[2] = (uint8_t)(password >> 24);
|
||||||
|
gen4_config[3] = (uint8_t)(password >> 16);
|
||||||
|
gen4_config[4] = (uint8_t)(password >> 8);
|
||||||
|
gen4_config[5] = (uint8_t)password;
|
||||||
|
|
||||||
|
if(dev_protocol == NfcDeviceProtocolMifareUl) {
|
||||||
|
gen4_config[6] = MagicGen4ShadowModeHighSpeedIgnore;
|
||||||
|
} else {
|
||||||
|
gen4_config[6] = MagicGen4ShadowModeIgnore;
|
||||||
|
}
|
||||||
|
gen4_config[7] = 0x00;
|
||||||
|
memset(gen4_config + 8, 0, 16);
|
||||||
|
gen4_config[24] = dev_data->nfc_data.atqa[0];
|
||||||
|
gen4_config[25] = dev_data->nfc_data.atqa[1];
|
||||||
|
gen4_config[26] = dev_data->nfc_data.sak;
|
||||||
|
|
||||||
|
furi_hal_nfc_activate_nfca(200, &cuid);
|
||||||
|
if(!magic_gen4_set_cfg(password, gen4_config, sizeof(gen4_config), false)) {
|
||||||
|
nfc_magic_worker->callback(
|
||||||
|
NfcMagicWorkerEventFail, nfc_magic_worker->context);
|
||||||
|
done = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(dev_protocol == NfcDeviceProtocolMifareClassic) {
|
||||||
|
MfClassicData* mfc_data = &dev_data->mf_classic_data;
|
||||||
|
size_t block_count = 64;
|
||||||
|
if(mfc_data->type == MfClassicType4k) block_count = 256;
|
||||||
|
for(size_t i = 0; i < block_count; i++) {
|
||||||
|
FURI_LOG_D(TAG, "Writing block %d", i);
|
||||||
|
if(!magic_gen4_write_blk(password, i, mfc_data->block[i].value)) {
|
||||||
|
FURI_LOG_E(TAG, "Failed to write %d block", i);
|
||||||
|
nfc_magic_worker->callback(
|
||||||
|
NfcMagicWorkerEventFail, nfc_magic_worker->context);
|
||||||
|
done = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if(dev_protocol == NfcDeviceProtocolMifareUl) {
|
||||||
|
MfUltralightData* mf_ul_data = &dev_data->mf_ul_data;
|
||||||
|
for(size_t i = 0; (i * 4) < mf_ul_data->data_read; i++) {
|
||||||
|
size_t data_offset = i * 4;
|
||||||
|
FURI_LOG_D(
|
||||||
|
TAG,
|
||||||
|
"Writing page %zu (%zu/%u)",
|
||||||
|
i,
|
||||||
|
data_offset,
|
||||||
|
mf_ul_data->data_read);
|
||||||
|
uint8_t* block = mf_ul_data->data + data_offset;
|
||||||
|
if(!magic_gen4_write_blk(password, i, block)) {
|
||||||
|
FURI_LOG_E(TAG, "Failed to write %zu page", i);
|
||||||
|
nfc_magic_worker->callback(
|
||||||
|
NfcMagicWorkerEventFail, nfc_magic_worker->context);
|
||||||
|
done = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t buffer[16] = {0};
|
||||||
|
|
||||||
|
for(size_t i = 0; i < 8; i++) {
|
||||||
|
memcpy(buffer, &mf_ul_data->signature[i * 4], 4); //-V1086
|
||||||
|
if(!magic_gen4_write_blk(password, 0xF2 + i, buffer)) {
|
||||||
|
FURI_LOG_E(TAG, "Failed to write signature block %d", i);
|
||||||
|
nfc_magic_worker->callback(
|
||||||
|
NfcMagicWorkerEventFail, nfc_magic_worker->context);
|
||||||
|
done = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer[0] = mf_ul_data->version.header;
|
||||||
|
buffer[1] = mf_ul_data->version.vendor_id;
|
||||||
|
buffer[2] = mf_ul_data->version.prod_type;
|
||||||
|
buffer[3] = mf_ul_data->version.prod_subtype;
|
||||||
|
if(!magic_gen4_write_blk(password, 0xFA, buffer)) {
|
||||||
|
FURI_LOG_E(TAG, "Failed to write version block 0");
|
||||||
|
nfc_magic_worker->callback(
|
||||||
|
NfcMagicWorkerEventFail, nfc_magic_worker->context);
|
||||||
|
done = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer[0] = mf_ul_data->version.prod_ver_major;
|
||||||
|
buffer[1] = mf_ul_data->version.prod_ver_minor;
|
||||||
|
buffer[2] = mf_ul_data->version.storage_size;
|
||||||
|
buffer[3] = mf_ul_data->version.protocol_type;
|
||||||
|
if(!magic_gen4_write_blk(password, 0xFB, buffer)) {
|
||||||
|
FURI_LOG_E(TAG, "Failed to write version block 1");
|
||||||
|
nfc_magic_worker->callback(
|
||||||
|
NfcMagicWorkerEventFail, nfc_magic_worker->context);
|
||||||
|
done = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
nfc_magic_worker->callback(
|
||||||
|
NfcMagicWorkerEventSuccess, nfc_magic_worker->context);
|
||||||
|
done = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
nfc_magic_worker->callback(NfcMagicWorkerEventSuccess, nfc_magic_worker->context);
|
} while(false);
|
||||||
break;
|
|
||||||
} else {
|
if(done) break;
|
||||||
if(card_found_notified) {
|
|
||||||
nfc_magic_worker->callback(
|
if(card_found_notified) {
|
||||||
NfcMagicWorkerEventNoCardDetected, nfc_magic_worker->context);
|
nfc_magic_worker->callback(
|
||||||
card_found_notified = false;
|
NfcMagicWorkerEventNoCardDetected, nfc_magic_worker->context);
|
||||||
}
|
card_found_notified = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
furi_delay_ms(300);
|
furi_delay_ms(300);
|
||||||
}
|
}
|
||||||
magic_deactivate();
|
magic_deactivate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void nfc_magic_worker_check(NfcMagicWorker* nfc_magic_worker) {
|
void nfc_magic_worker_check(NfcMagicWorker* nfc_magic_worker) {
|
||||||
|
NfcMagicDevice* magic_dev = nfc_magic_worker->magic_dev;
|
||||||
bool card_found_notified = false;
|
bool card_found_notified = false;
|
||||||
|
uint8_t gen4_config[MAGIC_GEN4_CONFIG_LEN];
|
||||||
|
|
||||||
while(nfc_magic_worker->state == NfcMagicWorkerStateCheck) {
|
while(nfc_magic_worker->state == NfcMagicWorkerStateCheck) {
|
||||||
if(magic_wupa()) {
|
magic_activate();
|
||||||
|
if(magic_gen1_wupa()) {
|
||||||
|
magic_dev->type = MagicTypeClassicGen1;
|
||||||
|
if(!card_found_notified) {
|
||||||
|
nfc_magic_worker->callback(
|
||||||
|
NfcMagicWorkerEventCardDetected, nfc_magic_worker->context);
|
||||||
|
card_found_notified = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
furi_hal_nfc_activate_nfca(200, &magic_dev->cuid);
|
||||||
|
nfc_magic_worker->callback(NfcMagicWorkerEventSuccess, nfc_magic_worker->context);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
magic_deactivate();
|
||||||
|
furi_delay_ms(300);
|
||||||
|
magic_activate();
|
||||||
|
|
||||||
|
furi_hal_nfc_activate_nfca(200, &magic_dev->cuid);
|
||||||
|
if(magic_gen4_get_cfg(magic_dev->password, gen4_config)) {
|
||||||
|
magic_dev->type = MagicTypeGen4;
|
||||||
if(!card_found_notified) {
|
if(!card_found_notified) {
|
||||||
nfc_magic_worker->callback(
|
nfc_magic_worker->callback(
|
||||||
NfcMagicWorkerEventCardDetected, nfc_magic_worker->context);
|
NfcMagicWorkerEventCardDetected, nfc_magic_worker->context);
|
||||||
@@ -138,12 +334,56 @@ void nfc_magic_worker_check(NfcMagicWorker* nfc_magic_worker) {
|
|||||||
|
|
||||||
nfc_magic_worker->callback(NfcMagicWorkerEventSuccess, nfc_magic_worker->context);
|
nfc_magic_worker->callback(NfcMagicWorkerEventSuccess, nfc_magic_worker->context);
|
||||||
break;
|
break;
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
if(card_found_notified) {
|
||||||
|
nfc_magic_worker->callback(
|
||||||
|
NfcMagicWorkerEventNoCardDetected, nfc_magic_worker->context);
|
||||||
|
card_found_notified = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
magic_deactivate();
|
||||||
|
furi_delay_ms(300);
|
||||||
|
}
|
||||||
|
|
||||||
|
magic_deactivate();
|
||||||
|
}
|
||||||
|
|
||||||
|
void nfc_magic_worker_rekey(NfcMagicWorker* nfc_magic_worker) {
|
||||||
|
NfcMagicDevice* magic_dev = nfc_magic_worker->magic_dev;
|
||||||
|
bool card_found_notified = false;
|
||||||
|
|
||||||
|
if(magic_dev->type != MagicTypeGen4) {
|
||||||
|
nfc_magic_worker->callback(NfcMagicWorkerEventCardDetected, nfc_magic_worker->context);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
while(nfc_magic_worker->state == NfcMagicWorkerStateRekey) {
|
||||||
|
magic_activate();
|
||||||
|
uint32_t cuid;
|
||||||
|
furi_hal_nfc_activate_nfca(200, &cuid);
|
||||||
|
if(cuid != magic_dev->cuid) {
|
||||||
if(card_found_notified) {
|
if(card_found_notified) {
|
||||||
nfc_magic_worker->callback(
|
nfc_magic_worker->callback(
|
||||||
NfcMagicWorkerEventNoCardDetected, nfc_magic_worker->context);
|
NfcMagicWorkerEventNoCardDetected, nfc_magic_worker->context);
|
||||||
card_found_notified = false;
|
card_found_notified = false;
|
||||||
}
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
nfc_magic_worker->callback(NfcMagicWorkerEventCardDetected, nfc_magic_worker->context);
|
||||||
|
card_found_notified = true;
|
||||||
|
|
||||||
|
if(magic_gen4_set_pwd(magic_dev->password, nfc_magic_worker->new_password)) {
|
||||||
|
magic_dev->password = nfc_magic_worker->new_password;
|
||||||
|
nfc_magic_worker->callback(NfcMagicWorkerEventSuccess, nfc_magic_worker->context);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(card_found_notified) { //-V547
|
||||||
|
nfc_magic_worker->callback(
|
||||||
|
NfcMagicWorkerEventNoCardDetected, nfc_magic_worker->context);
|
||||||
|
card_found_notified = false;
|
||||||
}
|
}
|
||||||
furi_delay_ms(300);
|
furi_delay_ms(300);
|
||||||
}
|
}
|
||||||
@@ -151,6 +391,10 @@ void nfc_magic_worker_check(NfcMagicWorker* nfc_magic_worker) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void nfc_magic_worker_wipe(NfcMagicWorker* nfc_magic_worker) {
|
void nfc_magic_worker_wipe(NfcMagicWorker* nfc_magic_worker) {
|
||||||
|
NfcMagicDevice* magic_dev = nfc_magic_worker->magic_dev;
|
||||||
|
bool card_found_notified = false;
|
||||||
|
bool card_wiped = false;
|
||||||
|
|
||||||
MfClassicBlock block;
|
MfClassicBlock block;
|
||||||
memset(&block, 0, sizeof(MfClassicBlock));
|
memset(&block, 0, sizeof(MfClassicBlock));
|
||||||
block.value[0] = 0x01;
|
block.value[0] = 0x01;
|
||||||
@@ -162,14 +406,48 @@ void nfc_magic_worker_wipe(NfcMagicWorker* nfc_magic_worker) {
|
|||||||
block.value[6] = 0x04;
|
block.value[6] = 0x04;
|
||||||
|
|
||||||
while(nfc_magic_worker->state == NfcMagicWorkerStateWipe) {
|
while(nfc_magic_worker->state == NfcMagicWorkerStateWipe) {
|
||||||
magic_deactivate();
|
do {
|
||||||
furi_delay_ms(300);
|
magic_deactivate();
|
||||||
if(!magic_wupa()) continue;
|
furi_delay_ms(300);
|
||||||
if(!magic_wipe()) continue;
|
if(!magic_activate()) break;
|
||||||
if(!magic_data_access_cmd()) continue;
|
if(magic_dev->type == MagicTypeClassicGen1) {
|
||||||
if(!magic_write_blk(0, &block)) continue;
|
if(!magic_gen1_wupa()) break;
|
||||||
nfc_magic_worker->callback(NfcMagicWorkerEventSuccess, nfc_magic_worker->context);
|
if(!card_found_notified) {
|
||||||
break;
|
nfc_magic_worker->callback(
|
||||||
|
NfcMagicWorkerEventCardDetected, nfc_magic_worker->context);
|
||||||
|
card_found_notified = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!magic_gen1_wipe()) break;
|
||||||
|
if(!magic_gen1_data_access_cmd()) break;
|
||||||
|
if(!magic_gen1_write_blk(0, &block)) break;
|
||||||
|
|
||||||
|
card_wiped = true;
|
||||||
|
nfc_magic_worker->callback(NfcMagicWorkerEventSuccess, nfc_magic_worker->context);
|
||||||
|
} else if(magic_dev->type == MagicTypeGen4) {
|
||||||
|
uint32_t cuid;
|
||||||
|
if(!furi_hal_nfc_activate_nfca(200, &cuid)) break;
|
||||||
|
if(cuid != magic_dev->cuid) break;
|
||||||
|
if(!card_found_notified) {
|
||||||
|
nfc_magic_worker->callback(
|
||||||
|
NfcMagicWorkerEventCardDetected, nfc_magic_worker->context);
|
||||||
|
card_found_notified = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!magic_gen4_wipe(magic_dev->password)) break;
|
||||||
|
|
||||||
|
card_wiped = true;
|
||||||
|
nfc_magic_worker->callback(NfcMagicWorkerEventSuccess, nfc_magic_worker->context);
|
||||||
|
}
|
||||||
|
} while(false);
|
||||||
|
|
||||||
|
if(card_wiped) break;
|
||||||
|
|
||||||
|
if(card_found_notified) {
|
||||||
|
nfc_magic_worker->callback(
|
||||||
|
NfcMagicWorkerEventNoCardDetected, nfc_magic_worker->context);
|
||||||
|
card_found_notified = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
magic_deactivate();
|
magic_deactivate();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <lib/nfc/nfc_device.h>
|
#include <lib/nfc/nfc_device.h>
|
||||||
|
#include "nfc_magic.h"
|
||||||
|
|
||||||
typedef struct NfcMagicWorker NfcMagicWorker;
|
typedef struct NfcMagicWorker NfcMagicWorker;
|
||||||
|
|
||||||
@@ -9,6 +10,7 @@ typedef enum {
|
|||||||
|
|
||||||
NfcMagicWorkerStateCheck,
|
NfcMagicWorkerStateCheck,
|
||||||
NfcMagicWorkerStateWrite,
|
NfcMagicWorkerStateWrite,
|
||||||
|
NfcMagicWorkerStateRekey,
|
||||||
NfcMagicWorkerStateWipe,
|
NfcMagicWorkerStateWipe,
|
||||||
|
|
||||||
NfcMagicWorkerStateStop,
|
NfcMagicWorkerStateStop,
|
||||||
@@ -33,6 +35,8 @@ void nfc_magic_worker_stop(NfcMagicWorker* nfc_magic_worker);
|
|||||||
void nfc_magic_worker_start(
|
void nfc_magic_worker_start(
|
||||||
NfcMagicWorker* nfc_magic_worker,
|
NfcMagicWorker* nfc_magic_worker,
|
||||||
NfcMagicWorkerState state,
|
NfcMagicWorkerState state,
|
||||||
|
NfcMagicDevice* magic_dev,
|
||||||
NfcDeviceData* dev_data,
|
NfcDeviceData* dev_data,
|
||||||
|
uint32_t new_password,
|
||||||
NfcMagicWorkerCallback callback,
|
NfcMagicWorkerCallback callback,
|
||||||
void* context);
|
void* context);
|
||||||
|
|||||||
@@ -3,11 +3,14 @@
|
|||||||
#include <furi.h>
|
#include <furi.h>
|
||||||
|
|
||||||
#include "nfc_magic_worker.h"
|
#include "nfc_magic_worker.h"
|
||||||
|
#include "lib/magic/common.h"
|
||||||
|
|
||||||
struct NfcMagicWorker {
|
struct NfcMagicWorker {
|
||||||
FuriThread* thread;
|
FuriThread* thread;
|
||||||
|
|
||||||
|
NfcMagicDevice* magic_dev;
|
||||||
NfcDeviceData* dev_data;
|
NfcDeviceData* dev_data;
|
||||||
|
uint32_t new_password;
|
||||||
|
|
||||||
NfcMagicWorkerCallback callback;
|
NfcMagicWorkerCallback callback;
|
||||||
void* context;
|
void* context;
|
||||||
@@ -21,4 +24,6 @@ void nfc_magic_worker_check(NfcMagicWorker* nfc_magic_worker);
|
|||||||
|
|
||||||
void nfc_magic_worker_write(NfcMagicWorker* nfc_magic_worker);
|
void nfc_magic_worker_write(NfcMagicWorker* nfc_magic_worker);
|
||||||
|
|
||||||
|
void nfc_magic_worker_rekey(NfcMagicWorker* nfc_magic_worker);
|
||||||
|
|
||||||
void nfc_magic_worker_wipe(NfcMagicWorker* nfc_magic_worker);
|
void nfc_magic_worker_wipe(NfcMagicWorker* nfc_magic_worker);
|
||||||
|
|||||||
50
applications/external/nfc_magic/scenes/nfc_magic_scene_actions.c
vendored
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
#include "../nfc_magic_i.h"
|
||||||
|
enum SubmenuIndex {
|
||||||
|
SubmenuIndexWrite,
|
||||||
|
SubmenuIndexWipe,
|
||||||
|
};
|
||||||
|
|
||||||
|
void nfc_magic_scene_actions_submenu_callback(void* context, uint32_t index) {
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
view_dispatcher_send_custom_event(nfc_magic->view_dispatcher, index);
|
||||||
|
}
|
||||||
|
|
||||||
|
void nfc_magic_scene_actions_on_enter(void* context) {
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
|
||||||
|
Submenu* submenu = nfc_magic->submenu;
|
||||||
|
submenu_add_item(
|
||||||
|
submenu, "Write", SubmenuIndexWrite, nfc_magic_scene_actions_submenu_callback, nfc_magic);
|
||||||
|
submenu_add_item(
|
||||||
|
submenu, "Wipe", SubmenuIndexWipe, nfc_magic_scene_actions_submenu_callback, nfc_magic);
|
||||||
|
|
||||||
|
submenu_set_selected_item(
|
||||||
|
submenu, scene_manager_get_scene_state(nfc_magic->scene_manager, NfcMagicSceneActions));
|
||||||
|
view_dispatcher_switch_to_view(nfc_magic->view_dispatcher, NfcMagicViewMenu);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool nfc_magic_scene_actions_on_event(void* context, SceneManagerEvent event) {
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
bool consumed = false;
|
||||||
|
|
||||||
|
if(event.type == SceneManagerEventTypeCustom) {
|
||||||
|
if(event.event == SubmenuIndexWrite) {
|
||||||
|
scene_manager_next_scene(nfc_magic->scene_manager, NfcMagicSceneFileSelect);
|
||||||
|
consumed = true;
|
||||||
|
} else if(event.event == SubmenuIndexWipe) {
|
||||||
|
scene_manager_next_scene(nfc_magic->scene_manager, NfcMagicSceneWipe);
|
||||||
|
consumed = true;
|
||||||
|
}
|
||||||
|
scene_manager_set_scene_state(nfc_magic->scene_manager, NfcMagicSceneActions, event.event);
|
||||||
|
} else if(event.type == SceneManagerEventTypeBack) {
|
||||||
|
consumed = scene_manager_search_and_switch_to_previous_scene(
|
||||||
|
nfc_magic->scene_manager, NfcMagicSceneStart);
|
||||||
|
}
|
||||||
|
|
||||||
|
return consumed;
|
||||||
|
}
|
||||||
|
|
||||||
|
void nfc_magic_scene_actions_on_exit(void* context) {
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
submenu_reset(nfc_magic->submenu);
|
||||||
|
}
|
||||||
@@ -42,7 +42,9 @@ void nfc_magic_scene_check_on_enter(void* context) {
|
|||||||
nfc_magic_worker_start(
|
nfc_magic_worker_start(
|
||||||
nfc_magic->worker,
|
nfc_magic->worker,
|
||||||
NfcMagicWorkerStateCheck,
|
NfcMagicWorkerStateCheck,
|
||||||
&nfc_magic->nfc_dev->dev_data,
|
nfc_magic->dev,
|
||||||
|
&nfc_magic->source_dev->dev_data,
|
||||||
|
nfc_magic->new_password,
|
||||||
nfc_magic_check_worker_callback,
|
nfc_magic_check_worker_callback,
|
||||||
nfc_magic);
|
nfc_magic);
|
||||||
nfc_magic_blink_start(nfc_magic);
|
nfc_magic_blink_start(nfc_magic);
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
ADD_SCENE(nfc_magic, start, Start)
|
ADD_SCENE(nfc_magic, start, Start)
|
||||||
|
ADD_SCENE(nfc_magic, key_input, KeyInput)
|
||||||
|
ADD_SCENE(nfc_magic, actions, Actions)
|
||||||
|
ADD_SCENE(nfc_magic, gen4_actions, Gen4Actions)
|
||||||
|
ADD_SCENE(nfc_magic, new_key_input, NewKeyInput)
|
||||||
ADD_SCENE(nfc_magic, file_select, FileSelect)
|
ADD_SCENE(nfc_magic, file_select, FileSelect)
|
||||||
ADD_SCENE(nfc_magic, write_confirm, WriteConfirm)
|
ADD_SCENE(nfc_magic, write_confirm, WriteConfirm)
|
||||||
ADD_SCENE(nfc_magic, wrong_card, WrongCard)
|
ADD_SCENE(nfc_magic, wrong_card, WrongCard)
|
||||||
@@ -8,5 +12,7 @@ ADD_SCENE(nfc_magic, success, Success)
|
|||||||
ADD_SCENE(nfc_magic, check, Check)
|
ADD_SCENE(nfc_magic, check, Check)
|
||||||
ADD_SCENE(nfc_magic, not_magic, NotMagic)
|
ADD_SCENE(nfc_magic, not_magic, NotMagic)
|
||||||
ADD_SCENE(nfc_magic, magic_info, MagicInfo)
|
ADD_SCENE(nfc_magic, magic_info, MagicInfo)
|
||||||
|
ADD_SCENE(nfc_magic, rekey, Rekey)
|
||||||
|
ADD_SCENE(nfc_magic, rekey_fail, RekeyFail)
|
||||||
ADD_SCENE(nfc_magic, wipe, Wipe)
|
ADD_SCENE(nfc_magic, wipe, Wipe)
|
||||||
ADD_SCENE(nfc_magic, wipe_fail, WipeFail)
|
ADD_SCENE(nfc_magic, wipe_fail, WipeFail)
|
||||||
|
|||||||
@@ -1,22 +1,60 @@
|
|||||||
#include "../nfc_magic_i.h"
|
#include "../nfc_magic_i.h"
|
||||||
|
|
||||||
static bool nfc_magic_scene_file_select_is_file_suitable(NfcDevice* nfc_dev) {
|
static bool nfc_magic_scene_file_select_is_file_suitable(NfcMagic* nfc_magic) {
|
||||||
return (nfc_dev->format == NfcDeviceSaveFormatMifareClassic) &&
|
NfcDevice* nfc_dev = nfc_magic->source_dev;
|
||||||
(nfc_dev->dev_data.mf_classic_data.type == MfClassicType1k) &&
|
if(nfc_dev->format == NfcDeviceSaveFormatMifareClassic) {
|
||||||
(nfc_dev->dev_data.nfc_data.uid_len == 4);
|
switch(nfc_magic->dev->type) {
|
||||||
|
case MagicTypeClassicGen1:
|
||||||
|
case MagicTypeClassicDirectWrite:
|
||||||
|
case MagicTypeClassicAPDU:
|
||||||
|
if((nfc_dev->dev_data.mf_classic_data.type != MfClassicType1k) ||
|
||||||
|
(nfc_dev->dev_data.nfc_data.uid_len != 4)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case MagicTypeGen4:
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else if(
|
||||||
|
(nfc_dev->format == NfcDeviceSaveFormatMifareUl) &&
|
||||||
|
(nfc_dev->dev_data.nfc_data.uid_len == 7)) {
|
||||||
|
switch(nfc_magic->dev->type) {
|
||||||
|
case MagicTypeUltralightGen1:
|
||||||
|
case MagicTypeUltralightDirectWrite:
|
||||||
|
case MagicTypeUltralightC_Gen1:
|
||||||
|
case MagicTypeUltralightC_DirectWrite:
|
||||||
|
case MagicTypeGen4:
|
||||||
|
switch(nfc_dev->dev_data.mf_ul_data.type) {
|
||||||
|
case MfUltralightTypeNTAGI2C1K:
|
||||||
|
case MfUltralightTypeNTAGI2C2K:
|
||||||
|
case MfUltralightTypeNTAGI2CPlus1K:
|
||||||
|
case MfUltralightTypeNTAGI2CPlus2K:
|
||||||
|
return false;
|
||||||
|
default:
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void nfc_magic_scene_file_select_on_enter(void* context) {
|
void nfc_magic_scene_file_select_on_enter(void* context) {
|
||||||
NfcMagic* nfc_magic = context;
|
NfcMagic* nfc_magic = context;
|
||||||
// Process file_select return
|
// Process file_select return
|
||||||
nfc_device_set_loading_callback(nfc_magic->nfc_dev, nfc_magic_show_loading_popup, nfc_magic);
|
nfc_device_set_loading_callback(
|
||||||
|
nfc_magic->source_dev, nfc_magic_show_loading_popup, nfc_magic);
|
||||||
|
|
||||||
if(!furi_string_size(nfc_magic->nfc_dev->load_path)) {
|
if(!furi_string_size(nfc_magic->source_dev->load_path)) {
|
||||||
furi_string_set_str(nfc_magic->nfc_dev->load_path, NFC_APP_FOLDER);
|
furi_string_set_str(nfc_magic->source_dev->load_path, NFC_APP_FOLDER);
|
||||||
}
|
}
|
||||||
|
if(nfc_file_select(nfc_magic->source_dev)) {
|
||||||
if(nfc_file_select(nfc_magic->nfc_dev)) {
|
if(nfc_magic_scene_file_select_is_file_suitable(nfc_magic)) {
|
||||||
if(nfc_magic_scene_file_select_is_file_suitable(nfc_magic->nfc_dev)) {
|
|
||||||
scene_manager_next_scene(nfc_magic->scene_manager, NfcMagicSceneWriteConfirm);
|
scene_manager_next_scene(nfc_magic->scene_manager, NfcMagicSceneWriteConfirm);
|
||||||
} else {
|
} else {
|
||||||
scene_manager_next_scene(nfc_magic->scene_manager, NfcMagicSceneWrongCard);
|
scene_manager_next_scene(nfc_magic->scene_manager, NfcMagicSceneWrongCard);
|
||||||
@@ -34,5 +72,5 @@ bool nfc_magic_scene_file_select_on_event(void* context, SceneManagerEvent event
|
|||||||
|
|
||||||
void nfc_magic_scene_file_select_on_exit(void* context) {
|
void nfc_magic_scene_file_select_on_exit(void* context) {
|
||||||
NfcMagic* nfc_magic = context;
|
NfcMagic* nfc_magic = context;
|
||||||
nfc_device_set_loading_callback(nfc_magic->nfc_dev, NULL, nfc_magic);
|
nfc_device_set_loading_callback(nfc_magic->source_dev, NULL, nfc_magic);
|
||||||
}
|
}
|
||||||
|
|||||||
70
applications/external/nfc_magic/scenes/nfc_magic_scene_gen4_actions.c
vendored
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
#include "../nfc_magic_i.h"
|
||||||
|
enum SubmenuIndex {
|
||||||
|
SubmenuIndexWrite,
|
||||||
|
SubmenuIndexChangePassword,
|
||||||
|
SubmenuIndexWipe,
|
||||||
|
};
|
||||||
|
|
||||||
|
void nfc_magic_scene_gen4_actions_submenu_callback(void* context, uint32_t index) {
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
view_dispatcher_send_custom_event(nfc_magic->view_dispatcher, index);
|
||||||
|
}
|
||||||
|
|
||||||
|
void nfc_magic_scene_gen4_actions_on_enter(void* context) {
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
|
||||||
|
Submenu* submenu = nfc_magic->submenu;
|
||||||
|
submenu_add_item(
|
||||||
|
submenu,
|
||||||
|
"Write",
|
||||||
|
SubmenuIndexWrite,
|
||||||
|
nfc_magic_scene_gen4_actions_submenu_callback,
|
||||||
|
nfc_magic);
|
||||||
|
submenu_add_item(
|
||||||
|
submenu,
|
||||||
|
"Change password",
|
||||||
|
SubmenuIndexChangePassword,
|
||||||
|
nfc_magic_scene_gen4_actions_submenu_callback,
|
||||||
|
nfc_magic);
|
||||||
|
submenu_add_item(
|
||||||
|
submenu,
|
||||||
|
"Wipe",
|
||||||
|
SubmenuIndexWipe,
|
||||||
|
nfc_magic_scene_gen4_actions_submenu_callback,
|
||||||
|
nfc_magic);
|
||||||
|
|
||||||
|
submenu_set_selected_item(
|
||||||
|
submenu,
|
||||||
|
scene_manager_get_scene_state(nfc_magic->scene_manager, NfcMagicSceneGen4Actions));
|
||||||
|
view_dispatcher_switch_to_view(nfc_magic->view_dispatcher, NfcMagicViewMenu);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool nfc_magic_scene_gen4_actions_on_event(void* context, SceneManagerEvent event) {
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
bool consumed = false;
|
||||||
|
|
||||||
|
if(event.type == SceneManagerEventTypeCustom) {
|
||||||
|
if(event.event == SubmenuIndexWrite) {
|
||||||
|
scene_manager_next_scene(nfc_magic->scene_manager, NfcMagicSceneFileSelect);
|
||||||
|
consumed = true;
|
||||||
|
} else if(event.event == SubmenuIndexChangePassword) {
|
||||||
|
scene_manager_next_scene(nfc_magic->scene_manager, NfcMagicSceneNewKeyInput);
|
||||||
|
consumed = true;
|
||||||
|
} else if(event.event == SubmenuIndexWipe) {
|
||||||
|
scene_manager_next_scene(nfc_magic->scene_manager, NfcMagicSceneWipe);
|
||||||
|
consumed = true;
|
||||||
|
}
|
||||||
|
scene_manager_set_scene_state(
|
||||||
|
nfc_magic->scene_manager, NfcMagicSceneGen4Actions, event.event);
|
||||||
|
} else if(event.type == SceneManagerEventTypeBack) {
|
||||||
|
consumed = scene_manager_search_and_switch_to_previous_scene(
|
||||||
|
nfc_magic->scene_manager, NfcMagicSceneStart);
|
||||||
|
}
|
||||||
|
|
||||||
|
return consumed;
|
||||||
|
}
|
||||||
|
|
||||||
|
void nfc_magic_scene_gen4_actions_on_exit(void* context) {
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
submenu_reset(nfc_magic->submenu);
|
||||||
|
}
|
||||||
45
applications/external/nfc_magic/scenes/nfc_magic_scene_key_input.c
vendored
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
#include "../nfc_magic_i.h"
|
||||||
|
|
||||||
|
void nfc_magic_scene_key_input_byte_input_callback(void* context) {
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
|
||||||
|
view_dispatcher_send_custom_event(
|
||||||
|
nfc_magic->view_dispatcher, NfcMagicCustomEventByteInputDone);
|
||||||
|
}
|
||||||
|
|
||||||
|
void nfc_magic_scene_key_input_on_enter(void* context) {
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
|
||||||
|
// Setup view
|
||||||
|
ByteInput* byte_input = nfc_magic->byte_input;
|
||||||
|
byte_input_set_header_text(byte_input, "Enter the password in hex");
|
||||||
|
byte_input_set_result_callback(
|
||||||
|
byte_input,
|
||||||
|
nfc_magic_scene_key_input_byte_input_callback,
|
||||||
|
NULL,
|
||||||
|
nfc_magic,
|
||||||
|
(uint8_t*)&nfc_magic->dev->password,
|
||||||
|
4);
|
||||||
|
view_dispatcher_switch_to_view(nfc_magic->view_dispatcher, NfcMagicViewByteInput);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool nfc_magic_scene_key_input_on_event(void* context, SceneManagerEvent event) {
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
bool consumed = false;
|
||||||
|
|
||||||
|
if(event.type == SceneManagerEventTypeCustom) {
|
||||||
|
if(event.event == NfcMagicCustomEventByteInputDone) {
|
||||||
|
scene_manager_next_scene(nfc_magic->scene_manager, NfcMagicSceneCheck);
|
||||||
|
consumed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return consumed;
|
||||||
|
}
|
||||||
|
|
||||||
|
void nfc_magic_scene_key_input_on_exit(void* context) {
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
|
||||||
|
// Clear view
|
||||||
|
byte_input_set_result_callback(nfc_magic->byte_input, NULL, NULL, NULL, NULL, 0);
|
||||||
|
byte_input_set_header_text(nfc_magic->byte_input, "");
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
#include "../nfc_magic_i.h"
|
#include "../nfc_magic_i.h"
|
||||||
|
#include "../lib/magic/types.h"
|
||||||
|
|
||||||
void nfc_magic_scene_magic_info_widget_callback(
|
void nfc_magic_scene_magic_info_widget_callback(
|
||||||
GuiButtonType result,
|
GuiButtonType result,
|
||||||
@@ -13,14 +14,18 @@ void nfc_magic_scene_magic_info_widget_callback(
|
|||||||
void nfc_magic_scene_magic_info_on_enter(void* context) {
|
void nfc_magic_scene_magic_info_on_enter(void* context) {
|
||||||
NfcMagic* nfc_magic = context;
|
NfcMagic* nfc_magic = context;
|
||||||
Widget* widget = nfc_magic->widget;
|
Widget* widget = nfc_magic->widget;
|
||||||
|
const char* card_type = nfc_magic_type(nfc_magic->dev->type);
|
||||||
|
|
||||||
notification_message(nfc_magic->notifications, &sequence_success);
|
notification_message(nfc_magic->notifications, &sequence_success);
|
||||||
|
|
||||||
widget_add_icon_element(widget, 73, 17, &I_DolphinCommon_56x48);
|
widget_add_icon_element(widget, 73, 17, &I_DolphinCommon_56x48);
|
||||||
widget_add_string_element(
|
widget_add_string_element(
|
||||||
widget, 3, 4, AlignLeft, AlignTop, FontPrimary, "Magic card detected");
|
widget, 3, 4, AlignLeft, AlignTop, FontPrimary, "Magic card detected");
|
||||||
|
widget_add_string_element(widget, 3, 17, AlignLeft, AlignTop, FontSecondary, card_type);
|
||||||
widget_add_button_element(
|
widget_add_button_element(
|
||||||
widget, GuiButtonTypeLeft, "Retry", nfc_magic_scene_magic_info_widget_callback, nfc_magic);
|
widget, GuiButtonTypeLeft, "Retry", nfc_magic_scene_magic_info_widget_callback, nfc_magic);
|
||||||
|
widget_add_button_element(
|
||||||
|
widget, GuiButtonTypeRight, "More", nfc_magic_scene_magic_info_widget_callback, nfc_magic);
|
||||||
|
|
||||||
// Setup and start worker
|
// Setup and start worker
|
||||||
view_dispatcher_switch_to_view(nfc_magic->view_dispatcher, NfcMagicViewWidget);
|
view_dispatcher_switch_to_view(nfc_magic->view_dispatcher, NfcMagicViewWidget);
|
||||||
@@ -33,6 +38,15 @@ bool nfc_magic_scene_magic_info_on_event(void* context, SceneManagerEvent event)
|
|||||||
if(event.type == SceneManagerEventTypeCustom) {
|
if(event.type == SceneManagerEventTypeCustom) {
|
||||||
if(event.event == GuiButtonTypeLeft) {
|
if(event.event == GuiButtonTypeLeft) {
|
||||||
consumed = scene_manager_previous_scene(nfc_magic->scene_manager);
|
consumed = scene_manager_previous_scene(nfc_magic->scene_manager);
|
||||||
|
} else if(event.event == GuiButtonTypeRight) {
|
||||||
|
MagicType type = nfc_magic->dev->type;
|
||||||
|
if(type == MagicTypeGen4) {
|
||||||
|
scene_manager_next_scene(nfc_magic->scene_manager, NfcMagicSceneGen4Actions);
|
||||||
|
consumed = true;
|
||||||
|
} else {
|
||||||
|
scene_manager_next_scene(nfc_magic->scene_manager, NfcMagicSceneActions);
|
||||||
|
consumed = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return consumed;
|
return consumed;
|
||||||
|
|||||||
45
applications/external/nfc_magic/scenes/nfc_magic_scene_new_key_input.c
vendored
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
#include "../nfc_magic_i.h"
|
||||||
|
|
||||||
|
void nfc_magic_scene_new_key_input_byte_input_callback(void* context) {
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
|
||||||
|
view_dispatcher_send_custom_event(
|
||||||
|
nfc_magic->view_dispatcher, NfcMagicCustomEventByteInputDone);
|
||||||
|
}
|
||||||
|
|
||||||
|
void nfc_magic_scene_new_key_input_on_enter(void* context) {
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
|
||||||
|
// Setup view
|
||||||
|
ByteInput* byte_input = nfc_magic->byte_input;
|
||||||
|
byte_input_set_header_text(byte_input, "Enter the password in hex");
|
||||||
|
byte_input_set_result_callback(
|
||||||
|
byte_input,
|
||||||
|
nfc_magic_scene_new_key_input_byte_input_callback,
|
||||||
|
NULL,
|
||||||
|
nfc_magic,
|
||||||
|
(uint8_t*)&nfc_magic->new_password,
|
||||||
|
4);
|
||||||
|
view_dispatcher_switch_to_view(nfc_magic->view_dispatcher, NfcMagicViewByteInput);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool nfc_magic_scene_new_key_input_on_event(void* context, SceneManagerEvent event) {
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
bool consumed = false;
|
||||||
|
|
||||||
|
if(event.type == SceneManagerEventTypeCustom) {
|
||||||
|
if(event.event == NfcMagicCustomEventByteInputDone) {
|
||||||
|
scene_manager_next_scene(nfc_magic->scene_manager, NfcMagicSceneRekey);
|
||||||
|
consumed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return consumed;
|
||||||
|
}
|
||||||
|
|
||||||
|
void nfc_magic_scene_new_key_input_on_exit(void* context) {
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
|
||||||
|
// Clear view
|
||||||
|
byte_input_set_result_callback(nfc_magic->byte_input, NULL, NULL, NULL, NULL, 0);
|
||||||
|
byte_input_set_header_text(nfc_magic->byte_input, "");
|
||||||
|
}
|
||||||
95
applications/external/nfc_magic/scenes/nfc_magic_scene_rekey.c
vendored
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
#include "../nfc_magic_i.h"
|
||||||
|
|
||||||
|
enum {
|
||||||
|
NfcMagicSceneRekeyStateCardSearch,
|
||||||
|
NfcMagicSceneRekeyStateCardFound,
|
||||||
|
};
|
||||||
|
|
||||||
|
bool nfc_magic_rekey_worker_callback(NfcMagicWorkerEvent event, void* context) {
|
||||||
|
furi_assert(context);
|
||||||
|
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
view_dispatcher_send_custom_event(nfc_magic->view_dispatcher, event);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void nfc_magic_scene_rekey_setup_view(NfcMagic* nfc_magic) {
|
||||||
|
Popup* popup = nfc_magic->popup;
|
||||||
|
popup_reset(popup);
|
||||||
|
uint32_t state = scene_manager_get_scene_state(nfc_magic->scene_manager, NfcMagicSceneRekey);
|
||||||
|
|
||||||
|
if(state == NfcMagicSceneRekeyStateCardSearch) {
|
||||||
|
popup_set_text(
|
||||||
|
nfc_magic->popup,
|
||||||
|
"Apply the\nsame card\nto the back",
|
||||||
|
128,
|
||||||
|
32,
|
||||||
|
AlignRight,
|
||||||
|
AlignCenter);
|
||||||
|
popup_set_icon(nfc_magic->popup, 0, 8, &I_NFC_manual_60x50);
|
||||||
|
} else {
|
||||||
|
popup_set_icon(popup, 12, 23, &I_Loading_24);
|
||||||
|
popup_set_header(popup, "Writing\nDon't move...", 52, 32, AlignLeft, AlignCenter);
|
||||||
|
}
|
||||||
|
|
||||||
|
view_dispatcher_switch_to_view(nfc_magic->view_dispatcher, NfcMagicViewPopup);
|
||||||
|
}
|
||||||
|
|
||||||
|
void nfc_magic_scene_rekey_on_enter(void* context) {
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
|
||||||
|
scene_manager_set_scene_state(
|
||||||
|
nfc_magic->scene_manager, NfcMagicSceneRekey, NfcMagicSceneRekeyStateCardSearch);
|
||||||
|
nfc_magic_scene_rekey_setup_view(nfc_magic);
|
||||||
|
|
||||||
|
// Setup and start worker
|
||||||
|
nfc_magic_worker_start(
|
||||||
|
nfc_magic->worker,
|
||||||
|
NfcMagicWorkerStateRekey,
|
||||||
|
nfc_magic->dev,
|
||||||
|
&nfc_magic->source_dev->dev_data,
|
||||||
|
nfc_magic->new_password,
|
||||||
|
nfc_magic_rekey_worker_callback,
|
||||||
|
nfc_magic);
|
||||||
|
nfc_magic_blink_start(nfc_magic);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool nfc_magic_scene_rekey_on_event(void* context, SceneManagerEvent event) {
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
bool consumed = false;
|
||||||
|
|
||||||
|
if(event.type == SceneManagerEventTypeCustom) {
|
||||||
|
if(event.event == NfcMagicWorkerEventSuccess) {
|
||||||
|
nfc_magic->dev->password = nfc_magic->new_password;
|
||||||
|
scene_manager_next_scene(nfc_magic->scene_manager, NfcMagicSceneSuccess);
|
||||||
|
consumed = true;
|
||||||
|
} else if(event.event == NfcMagicWorkerEventFail) {
|
||||||
|
scene_manager_next_scene(nfc_magic->scene_manager, NfcMagicSceneRekeyFail);
|
||||||
|
consumed = true;
|
||||||
|
} else if(event.event == NfcMagicWorkerEventCardDetected) {
|
||||||
|
scene_manager_set_scene_state(
|
||||||
|
nfc_magic->scene_manager, NfcMagicSceneRekey, NfcMagicSceneRekeyStateCardFound);
|
||||||
|
nfc_magic_scene_rekey_setup_view(nfc_magic);
|
||||||
|
consumed = true;
|
||||||
|
} else if(event.event == NfcMagicWorkerEventNoCardDetected) {
|
||||||
|
scene_manager_set_scene_state(
|
||||||
|
nfc_magic->scene_manager, NfcMagicSceneRekey, NfcMagicSceneRekeyStateCardSearch);
|
||||||
|
nfc_magic_scene_rekey_setup_view(nfc_magic);
|
||||||
|
consumed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return consumed;
|
||||||
|
}
|
||||||
|
|
||||||
|
void nfc_magic_scene_rekey_on_exit(void* context) {
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
|
||||||
|
nfc_magic_worker_stop(nfc_magic->worker);
|
||||||
|
scene_manager_set_scene_state(
|
||||||
|
nfc_magic->scene_manager, NfcMagicSceneRekey, NfcMagicSceneRekeyStateCardSearch);
|
||||||
|
// Clear view
|
||||||
|
popup_reset(nfc_magic->popup);
|
||||||
|
|
||||||
|
nfc_magic_blink_stop(nfc_magic);
|
||||||
|
}
|
||||||
50
applications/external/nfc_magic/scenes/nfc_magic_scene_rekey_fail.c
vendored
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
#include "../nfc_magic_i.h"
|
||||||
|
|
||||||
|
void nfc_magic_scene_rekey_fail_widget_callback(
|
||||||
|
GuiButtonType result,
|
||||||
|
InputType type,
|
||||||
|
void* context) {
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
if(type == InputTypeShort) {
|
||||||
|
view_dispatcher_send_custom_event(nfc_magic->view_dispatcher, result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void nfc_magic_scene_rekey_fail_on_enter(void* context) {
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
Widget* widget = nfc_magic->widget;
|
||||||
|
|
||||||
|
notification_message(nfc_magic->notifications, &sequence_error);
|
||||||
|
|
||||||
|
widget_add_icon_element(widget, 72, 17, &I_DolphinCommon_56x48);
|
||||||
|
widget_add_string_element(
|
||||||
|
widget, 7, 4, AlignLeft, AlignTop, FontPrimary, "Can't change password!");
|
||||||
|
|
||||||
|
widget_add_button_element(
|
||||||
|
widget, GuiButtonTypeLeft, "Finish", nfc_magic_scene_rekey_fail_widget_callback, nfc_magic);
|
||||||
|
|
||||||
|
// Setup and start worker
|
||||||
|
view_dispatcher_switch_to_view(nfc_magic->view_dispatcher, NfcMagicViewWidget);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool nfc_magic_scene_rekey_fail_on_event(void* context, SceneManagerEvent event) {
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
bool consumed = false;
|
||||||
|
|
||||||
|
if(event.type == SceneManagerEventTypeCustom) {
|
||||||
|
if(event.event == GuiButtonTypeLeft) {
|
||||||
|
consumed = scene_manager_search_and_switch_to_previous_scene(
|
||||||
|
nfc_magic->scene_manager, NfcMagicSceneStart);
|
||||||
|
}
|
||||||
|
} else if(event.type == SceneManagerEventTypeBack) {
|
||||||
|
consumed = scene_manager_search_and_switch_to_previous_scene(
|
||||||
|
nfc_magic->scene_manager, NfcMagicSceneStart);
|
||||||
|
}
|
||||||
|
return consumed;
|
||||||
|
}
|
||||||
|
|
||||||
|
void nfc_magic_scene_rekey_fail_on_exit(void* context) {
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
|
||||||
|
widget_reset(nfc_magic->widget);
|
||||||
|
}
|
||||||
@@ -1,8 +1,7 @@
|
|||||||
#include "../nfc_magic_i.h"
|
#include "../nfc_magic_i.h"
|
||||||
enum SubmenuIndex {
|
enum SubmenuIndex {
|
||||||
SubmenuIndexCheck,
|
SubmenuIndexCheck,
|
||||||
SubmenuIndexWriteGen1A,
|
SubmenuIndexAuthenticateGen4,
|
||||||
SubmenuIndexWipe,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void nfc_magic_scene_start_submenu_callback(void* context, uint32_t index) {
|
void nfc_magic_scene_start_submenu_callback(void* context, uint32_t index) {
|
||||||
@@ -22,12 +21,10 @@ void nfc_magic_scene_start_on_enter(void* context) {
|
|||||||
nfc_magic);
|
nfc_magic);
|
||||||
submenu_add_item(
|
submenu_add_item(
|
||||||
submenu,
|
submenu,
|
||||||
"Write Gen1A",
|
"Authenticate Gen4",
|
||||||
SubmenuIndexWriteGen1A,
|
SubmenuIndexAuthenticateGen4,
|
||||||
nfc_magic_scene_start_submenu_callback,
|
nfc_magic_scene_start_submenu_callback,
|
||||||
nfc_magic);
|
nfc_magic);
|
||||||
submenu_add_item(
|
|
||||||
submenu, "Wipe", SubmenuIndexWipe, nfc_magic_scene_start_submenu_callback, nfc_magic);
|
|
||||||
|
|
||||||
submenu_set_selected_item(
|
submenu_set_selected_item(
|
||||||
submenu, scene_manager_get_scene_state(nfc_magic->scene_manager, NfcMagicSceneStart));
|
submenu, scene_manager_get_scene_state(nfc_magic->scene_manager, NfcMagicSceneStart));
|
||||||
@@ -40,23 +37,13 @@ bool nfc_magic_scene_start_on_event(void* context, SceneManagerEvent event) {
|
|||||||
|
|
||||||
if(event.type == SceneManagerEventTypeCustom) {
|
if(event.type == SceneManagerEventTypeCustom) {
|
||||||
if(event.event == SubmenuIndexCheck) {
|
if(event.event == SubmenuIndexCheck) {
|
||||||
|
nfc_magic->dev->password = MAGIC_GEN4_DEFAULT_PWD;
|
||||||
scene_manager_set_scene_state(
|
scene_manager_set_scene_state(
|
||||||
nfc_magic->scene_manager, NfcMagicSceneStart, SubmenuIndexCheck);
|
nfc_magic->scene_manager, NfcMagicSceneStart, SubmenuIndexCheck);
|
||||||
scene_manager_next_scene(nfc_magic->scene_manager, NfcMagicSceneCheck);
|
scene_manager_next_scene(nfc_magic->scene_manager, NfcMagicSceneCheck);
|
||||||
consumed = true;
|
consumed = true;
|
||||||
} else if(event.event == SubmenuIndexWriteGen1A) {
|
} else if(event.event == SubmenuIndexAuthenticateGen4) {
|
||||||
// Explicitly save state in each branch so that the
|
scene_manager_next_scene(nfc_magic->scene_manager, NfcMagicSceneKeyInput);
|
||||||
// correct option is reselected if the user cancels
|
|
||||||
// loading a file.
|
|
||||||
scene_manager_set_scene_state(
|
|
||||||
nfc_magic->scene_manager, NfcMagicSceneStart, SubmenuIndexWriteGen1A);
|
|
||||||
scene_manager_next_scene(nfc_magic->scene_manager, NfcMagicSceneFileSelect);
|
|
||||||
consumed = true;
|
|
||||||
} else if(event.event == SubmenuIndexWipe) {
|
|
||||||
scene_manager_set_scene_state(
|
|
||||||
nfc_magic->scene_manager, NfcMagicSceneStart, SubmenuIndexWipe);
|
|
||||||
scene_manager_next_scene(nfc_magic->scene_manager, NfcMagicSceneWipe);
|
|
||||||
consumed = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,12 @@ static void nfc_magic_scene_wipe_setup_view(NfcMagic* nfc_magic) {
|
|||||||
if(state == NfcMagicSceneWipeStateCardSearch) {
|
if(state == NfcMagicSceneWipeStateCardSearch) {
|
||||||
popup_set_icon(nfc_magic->popup, 0, 8, &I_NFC_manual_60x50);
|
popup_set_icon(nfc_magic->popup, 0, 8, &I_NFC_manual_60x50);
|
||||||
popup_set_text(
|
popup_set_text(
|
||||||
nfc_magic->popup, "Apply card to\nthe back", 128, 32, AlignRight, AlignCenter);
|
nfc_magic->popup,
|
||||||
|
"Apply the\nsame card\nto the back",
|
||||||
|
128,
|
||||||
|
32,
|
||||||
|
AlignRight,
|
||||||
|
AlignCenter);
|
||||||
} else {
|
} else {
|
||||||
popup_set_icon(popup, 12, 23, &I_Loading_24);
|
popup_set_icon(popup, 12, 23, &I_Loading_24);
|
||||||
popup_set_header(popup, "Wiping\nDon't move...", 52, 32, AlignLeft, AlignCenter);
|
popup_set_header(popup, "Wiping\nDon't move...", 52, 32, AlignLeft, AlignCenter);
|
||||||
@@ -42,7 +47,9 @@ void nfc_magic_scene_wipe_on_enter(void* context) {
|
|||||||
nfc_magic_worker_start(
|
nfc_magic_worker_start(
|
||||||
nfc_magic->worker,
|
nfc_magic->worker,
|
||||||
NfcMagicWorkerStateWipe,
|
NfcMagicWorkerStateWipe,
|
||||||
&nfc_magic->nfc_dev->dev_data,
|
nfc_magic->dev,
|
||||||
|
&nfc_magic->source_dev->dev_data,
|
||||||
|
nfc_magic->new_password,
|
||||||
nfc_magic_wipe_worker_callback,
|
nfc_magic_wipe_worker_callback,
|
||||||
nfc_magic);
|
nfc_magic);
|
||||||
nfc_magic_blink_start(nfc_magic);
|
nfc_magic_blink_start(nfc_magic);
|
||||||
|
|||||||
@@ -21,7 +21,12 @@ static void nfc_magic_scene_write_setup_view(NfcMagic* nfc_magic) {
|
|||||||
|
|
||||||
if(state == NfcMagicSceneWriteStateCardSearch) {
|
if(state == NfcMagicSceneWriteStateCardSearch) {
|
||||||
popup_set_text(
|
popup_set_text(
|
||||||
nfc_magic->popup, "Apply card to\nthe back", 128, 32, AlignRight, AlignCenter);
|
nfc_magic->popup,
|
||||||
|
"Apply the\nsame card\nto the back",
|
||||||
|
128,
|
||||||
|
32,
|
||||||
|
AlignRight,
|
||||||
|
AlignCenter);
|
||||||
popup_set_icon(nfc_magic->popup, 0, 8, &I_NFC_manual_60x50);
|
popup_set_icon(nfc_magic->popup, 0, 8, &I_NFC_manual_60x50);
|
||||||
} else {
|
} else {
|
||||||
popup_set_icon(popup, 12, 23, &I_Loading_24);
|
popup_set_icon(popup, 12, 23, &I_Loading_24);
|
||||||
@@ -42,7 +47,9 @@ void nfc_magic_scene_write_on_enter(void* context) {
|
|||||||
nfc_magic_worker_start(
|
nfc_magic_worker_start(
|
||||||
nfc_magic->worker,
|
nfc_magic->worker,
|
||||||
NfcMagicWorkerStateWrite,
|
NfcMagicWorkerStateWrite,
|
||||||
&nfc_magic->nfc_dev->dev_data,
|
nfc_magic->dev,
|
||||||
|
&nfc_magic->source_dev->dev_data,
|
||||||
|
nfc_magic->new_password,
|
||||||
nfc_magic_write_worker_callback,
|
nfc_magic_write_worker_callback,
|
||||||
nfc_magic);
|
nfc_magic);
|
||||||
nfc_magic_blink_start(nfc_magic);
|
nfc_magic_blink_start(nfc_magic);
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ void nfc_magic_scene_wrong_card_on_enter(void* context) {
|
|||||||
AlignLeft,
|
AlignLeft,
|
||||||
AlignTop,
|
AlignTop,
|
||||||
FontSecondary,
|
FontSecondary,
|
||||||
"Writing is supported\nonly for 4 bytes UID\nMifare Classic 1k");
|
"Writing this file is\nnot supported for\nthis magic card.");
|
||||||
widget_add_button_element(
|
widget_add_button_element(
|
||||||
widget, GuiButtonTypeLeft, "Retry", nfc_magic_scene_wrong_card_widget_callback, nfc_magic);
|
widget, GuiButtonTypeLeft, "Retry", nfc_magic_scene_wrong_card_widget_callback, nfc_magic);
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ App(
|
|||||||
stack_size=4 * 1024,
|
stack_size=4 * 1024,
|
||||||
order=30,
|
order=30,
|
||||||
fap_icon="125_10px.png",
|
fap_icon="125_10px.png",
|
||||||
fap_category="Tools",
|
fap_category="NFC",
|
||||||
fap_libs=["mbedtls"],
|
fap_libs=["mbedtls"],
|
||||||
fap_private_libs=[
|
fap_private_libs=[
|
||||||
Lib(
|
Lib(
|
||||||
|
|||||||
16
applications/external/subghz_remote_configurator/application.fam
vendored
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
App(
|
||||||
|
appid="subrem_configurator",
|
||||||
|
name="Remote Maker",
|
||||||
|
apptype=FlipperAppType.EXTERNAL,
|
||||||
|
entry_point="subghz_remote_config_app",
|
||||||
|
requires=[
|
||||||
|
"gui",
|
||||||
|
"dialogs",
|
||||||
|
],
|
||||||
|
stack_size=2 * 1024,
|
||||||
|
order=50,
|
||||||
|
fap_description="File Editor for the SubGhz Remote app",
|
||||||
|
fap_category="Sub-Ghz",
|
||||||
|
fap_icon_assets="icons",
|
||||||
|
fap_icon="icons/subrem_10px.png",
|
||||||
|
)
|
||||||
52
applications/external/subghz_remote_configurator/helpers/subrem_custom_event.h
vendored
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
SubRemEditMenuStateUP = 0,
|
||||||
|
SubRemEditMenuStateDOWN,
|
||||||
|
SubRemEditMenuStateLEFT,
|
||||||
|
SubRemEditMenuStateRIGHT,
|
||||||
|
SubRemEditMenuStateOK,
|
||||||
|
} SubRemEditMenuState;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
// SubmenuIndex
|
||||||
|
SubmenuIndexSubRemEditMapFile = 0,
|
||||||
|
SubmenuIndexSubRemNewMapFile,
|
||||||
|
SubmenuIndexSubRemRemoteView,
|
||||||
|
SubmenuIndexSubRemAbout,
|
||||||
|
|
||||||
|
// EditSubmenuIndex
|
||||||
|
EditSubmenuIndexEditLabel,
|
||||||
|
EditSubmenuIndexEditFile,
|
||||||
|
|
||||||
|
// SubRemCustomEvent
|
||||||
|
SubRemCustomEventViewRemoteStartUP = 100,
|
||||||
|
SubRemCustomEventViewRemoteStartDOWN,
|
||||||
|
SubRemCustomEventViewRemoteStartLEFT,
|
||||||
|
SubRemCustomEventViewRemoteStartRIGHT,
|
||||||
|
SubRemCustomEventViewRemoteStartOK,
|
||||||
|
SubRemCustomEventViewRemoteBack,
|
||||||
|
SubRemCustomEventViewRemoteStop,
|
||||||
|
SubRemCustomEventViewRemoteForcedStop,
|
||||||
|
|
||||||
|
SubRemCustomEventViewEditMenuBack,
|
||||||
|
SubRemCustomEventViewEditMenuUP,
|
||||||
|
SubRemCustomEventViewEditMenuDOWN,
|
||||||
|
SubRemCustomEventViewEditMenuEdit,
|
||||||
|
SubRemCustomEventViewEditMenuSave,
|
||||||
|
|
||||||
|
SubRemCustomEventSceneEditsubmenu,
|
||||||
|
SubRemCustomEventSceneEditLabelInputDone,
|
||||||
|
SubRemCustomEventSceneEditLabelWidgetAcces,
|
||||||
|
SubRemCustomEventSceneEditLabelWidgetBack,
|
||||||
|
|
||||||
|
SubRemCustomEventSceneEditOpenSubErrorPopup,
|
||||||
|
|
||||||
|
SubRemCustomEventSceneEditPreviewSaved,
|
||||||
|
|
||||||
|
SubRemCustomEventSceneNewName,
|
||||||
|
|
||||||
|
// // SceneStates
|
||||||
|
// SubRemSceneOpenMapFileStateOpen,
|
||||||
|
// SubRemSceneOpenMapFileStateEdit,
|
||||||
|
} SubRemCustomEvent;
|
||||||
180
applications/external/subghz_remote_configurator/helpers/subrem_presets.c
vendored
Normal file
@@ -0,0 +1,180 @@
|
|||||||
|
#include "subrem_presets.h"
|
||||||
|
|
||||||
|
#define TAG "SubRemPresets"
|
||||||
|
|
||||||
|
SubRemSubFilePreset* subrem_sub_file_preset_alloc() {
|
||||||
|
SubRemSubFilePreset* sub_preset = malloc(sizeof(SubRemSubFilePreset));
|
||||||
|
|
||||||
|
sub_preset->fff_data = flipper_format_string_alloc();
|
||||||
|
sub_preset->file_path = furi_string_alloc();
|
||||||
|
sub_preset->protocaol_name = furi_string_alloc();
|
||||||
|
sub_preset->label = furi_string_alloc();
|
||||||
|
|
||||||
|
sub_preset->freq_preset.name = furi_string_alloc();
|
||||||
|
|
||||||
|
sub_preset->type = SubGhzProtocolTypeUnknown;
|
||||||
|
sub_preset->load_state = SubRemLoadSubStateNotSet;
|
||||||
|
|
||||||
|
return sub_preset;
|
||||||
|
}
|
||||||
|
|
||||||
|
void subrem_sub_file_preset_free(SubRemSubFilePreset* sub_preset) {
|
||||||
|
furi_assert(sub_preset);
|
||||||
|
|
||||||
|
furi_string_free(sub_preset->label);
|
||||||
|
furi_string_free(sub_preset->protocaol_name);
|
||||||
|
furi_string_free(sub_preset->file_path);
|
||||||
|
flipper_format_free(sub_preset->fff_data);
|
||||||
|
|
||||||
|
furi_string_free(sub_preset->freq_preset.name);
|
||||||
|
|
||||||
|
free(sub_preset);
|
||||||
|
}
|
||||||
|
|
||||||
|
void subrem_sub_file_preset_reset(SubRemSubFilePreset* sub_preset) {
|
||||||
|
furi_assert(sub_preset);
|
||||||
|
|
||||||
|
furi_string_set_str(sub_preset->label, "");
|
||||||
|
furi_string_reset(sub_preset->protocaol_name);
|
||||||
|
furi_string_reset(sub_preset->file_path);
|
||||||
|
|
||||||
|
Stream* fff_data_stream = flipper_format_get_raw_stream(sub_preset->fff_data);
|
||||||
|
stream_clean(fff_data_stream);
|
||||||
|
|
||||||
|
sub_preset->type = SubGhzProtocolTypeUnknown;
|
||||||
|
sub_preset->load_state = SubRemLoadSubStateNotSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
SubRemLoadSubState subrem_sub_preset_load(
|
||||||
|
SubRemSubFilePreset* sub_preset,
|
||||||
|
SubGhzTxRx* txrx,
|
||||||
|
FlipperFormat* fff_data_file) {
|
||||||
|
furi_assert(sub_preset);
|
||||||
|
furi_assert(txrx);
|
||||||
|
furi_assert(fff_data_file);
|
||||||
|
|
||||||
|
Stream* fff_data_stream = flipper_format_get_raw_stream(sub_preset->fff_data);
|
||||||
|
|
||||||
|
SubRemLoadSubState ret;
|
||||||
|
FuriString* temp_str = furi_string_alloc();
|
||||||
|
uint32_t temp_data32;
|
||||||
|
uint32_t repeat = 200;
|
||||||
|
|
||||||
|
ret = SubRemLoadSubStateError;
|
||||||
|
|
||||||
|
do {
|
||||||
|
stream_clean(fff_data_stream);
|
||||||
|
if(!flipper_format_read_header(fff_data_file, temp_str, &temp_data32)) {
|
||||||
|
FURI_LOG_E(TAG, "Missing or incorrect header");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(((!strcmp(furi_string_get_cstr(temp_str), SUBGHZ_KEY_FILE_TYPE)) ||
|
||||||
|
(!strcmp(furi_string_get_cstr(temp_str), SUBGHZ_RAW_FILE_TYPE))) &&
|
||||||
|
temp_data32 == SUBGHZ_KEY_FILE_VERSION) {
|
||||||
|
} else {
|
||||||
|
FURI_LOG_E(TAG, "Type or version mismatch");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
SubGhzSetting* setting = subghz_txrx_get_setting(txrx);
|
||||||
|
|
||||||
|
//Load frequency or using default from settings
|
||||||
|
ret = SubRemLoadSubStateErrorFreq;
|
||||||
|
if(!flipper_format_read_uint32(fff_data_file, "Frequency", &temp_data32, 1)) {
|
||||||
|
FURI_LOG_W(TAG, "Cannot read frequency. Set default frequency");
|
||||||
|
sub_preset->freq_preset.frequency = subghz_setting_get_default_frequency(setting);
|
||||||
|
} else if(!furi_hal_subghz_is_tx_allowed(temp_data32)) {
|
||||||
|
FURI_LOG_E(TAG, "This frequency can only be used for RX");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
sub_preset->freq_preset.frequency = temp_data32;
|
||||||
|
|
||||||
|
//Load preset
|
||||||
|
ret = SubRemLoadSubStateErrorMod;
|
||||||
|
if(!flipper_format_read_string(fff_data_file, "Preset", temp_str)) {
|
||||||
|
FURI_LOG_E(TAG, "Missing Preset");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
furi_string_set_str(
|
||||||
|
temp_str, subghz_txrx_get_preset_name(txrx, furi_string_get_cstr(temp_str)));
|
||||||
|
if(!strcmp(furi_string_get_cstr(temp_str), "")) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!strcmp(furi_string_get_cstr(temp_str), "CUSTOM")) {
|
||||||
|
FURI_LOG_E(TAG, "CUSTOM preset is not supported");
|
||||||
|
break;
|
||||||
|
// TODO Custom preset loading logic if need
|
||||||
|
// sub_preset->freq_preset.preset_index =
|
||||||
|
// subghz_setting_get_inx_preset_by_name(setting, furi_string_get_cstr(temp_str));
|
||||||
|
}
|
||||||
|
|
||||||
|
furi_string_set(sub_preset->freq_preset.name, temp_str);
|
||||||
|
|
||||||
|
// Load protocol
|
||||||
|
ret = SubRemLoadSubStateErrorProtocol;
|
||||||
|
if(!flipper_format_read_string(fff_data_file, "Protocol", temp_str)) {
|
||||||
|
FURI_LOG_E(TAG, "Missing Protocol");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
FlipperFormat* fff_data = sub_preset->fff_data;
|
||||||
|
if(!strcmp(furi_string_get_cstr(temp_str), "RAW")) {
|
||||||
|
//if RAW
|
||||||
|
subghz_protocol_raw_gen_fff_data(
|
||||||
|
fff_data, furi_string_get_cstr(sub_preset->file_path));
|
||||||
|
} else {
|
||||||
|
stream_copy_full(
|
||||||
|
flipper_format_get_raw_stream(fff_data_file),
|
||||||
|
flipper_format_get_raw_stream(fff_data));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(subghz_txrx_load_decoder_by_name_protocol(txrx, furi_string_get_cstr(temp_str))) {
|
||||||
|
SubGhzProtocolStatus status =
|
||||||
|
subghz_protocol_decoder_base_deserialize(subghz_txrx_get_decoder(txrx), fff_data);
|
||||||
|
if(status != SubGhzProtocolStatusOk) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
FURI_LOG_E(TAG, "Protocol not found");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
const SubGhzProtocol* protocol = subghz_txrx_get_decoder(txrx)->protocol;
|
||||||
|
|
||||||
|
if(protocol->flag & SubGhzProtocolFlag_Send) {
|
||||||
|
if((protocol->type == SubGhzProtocolTypeStatic) ||
|
||||||
|
(protocol->type == SubGhzProtocolTypeDynamic) ||
|
||||||
|
// TODO: BINRAW It probably works, but checks are needed.
|
||||||
|
// (protocol->type == SubGhzProtocolTypeBinRAW) ||
|
||||||
|
(protocol->type == SubGhzProtocolTypeRAW)) {
|
||||||
|
sub_preset->type = protocol->type;
|
||||||
|
} else {
|
||||||
|
FURI_LOG_E(TAG, "Unsuported Protocol");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
furi_string_set(sub_preset->protocaol_name, temp_str);
|
||||||
|
} else {
|
||||||
|
FURI_LOG_E(TAG, "Protocol does not support transmission");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!flipper_format_insert_or_update_uint32(fff_data, "Repeat", &repeat, 1)) {
|
||||||
|
FURI_LOG_E(TAG, "Unable Repeat");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = SubRemLoadSubStateOK;
|
||||||
|
|
||||||
|
#if FURI_DEBUG
|
||||||
|
FURI_LOG_I(TAG, "%-16s - protocol Loaded", furi_string_get_cstr(sub_preset->label));
|
||||||
|
#endif
|
||||||
|
} while(false);
|
||||||
|
|
||||||
|
furi_string_free(temp_str);
|
||||||
|
sub_preset->load_state = ret;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
39
applications/external/subghz_remote_configurator/helpers/subrem_presets.h
vendored
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "subrem_types.h"
|
||||||
|
#include "txrx/subghz_txrx.h"
|
||||||
|
|
||||||
|
#include <flipper_format/flipper_format_i.h>
|
||||||
|
#include <lib/subghz/types.h>
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
FuriString* name;
|
||||||
|
uint32_t frequency;
|
||||||
|
// size_t preset_index; // Need for custom preset
|
||||||
|
} FreqPreset;
|
||||||
|
|
||||||
|
// Sub File preset
|
||||||
|
typedef struct {
|
||||||
|
FlipperFormat* fff_data;
|
||||||
|
FreqPreset freq_preset;
|
||||||
|
FuriString* file_path;
|
||||||
|
FuriString* protocaol_name;
|
||||||
|
FuriString* label;
|
||||||
|
SubGhzProtocolType type;
|
||||||
|
SubRemLoadSubState load_state;
|
||||||
|
} SubRemSubFilePreset;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
SubRemSubFilePreset* subs_preset[SubRemSubKeyNameMaxCount];
|
||||||
|
} SubRemMapPreset;
|
||||||
|
|
||||||
|
SubRemSubFilePreset* subrem_sub_file_preset_alloc();
|
||||||
|
|
||||||
|
void subrem_sub_file_preset_free(SubRemSubFilePreset* sub_preset);
|
||||||
|
|
||||||
|
void subrem_sub_file_preset_reset(SubRemSubFilePreset* sub_preset);
|
||||||
|
|
||||||
|
SubRemLoadSubState subrem_sub_preset_load(
|
||||||
|
SubRemSubFilePreset* sub_preset,
|
||||||
|
SubGhzTxRx* txrx,
|
||||||
|
FlipperFormat* fff_data_file);
|
||||||
48
applications/external/subghz_remote_configurator/helpers/subrem_types.h
vendored
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <furi.h>
|
||||||
|
#include <furi_hal.h>
|
||||||
|
|
||||||
|
#define SUBREM_APP_APP_FILE_VERSION 1
|
||||||
|
#define SUBREM_APP_APP_FILE_TYPE "Flipper SubRem Map file"
|
||||||
|
#define SUBREM_APP_EXTENSION ".txt"
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
SubRemSubKeyNameUp = (0U),
|
||||||
|
SubRemSubKeyNameDown,
|
||||||
|
SubRemSubKeyNameLeft,
|
||||||
|
SubRemSubKeyNameRight,
|
||||||
|
SubRemSubKeyNameOk,
|
||||||
|
SubRemSubKeyNameMaxCount,
|
||||||
|
} SubRemSubKeyName;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
SubRemViewIDSubmenu,
|
||||||
|
SubRemViewIDWidget,
|
||||||
|
SubRemViewIDPopup,
|
||||||
|
SubRemViewIDTextInput,
|
||||||
|
SubRemViewIDRemote,
|
||||||
|
SubRemViewIDEditMenu,
|
||||||
|
} SubRemViewID;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
SubRemLoadSubStateNotSet = 0,
|
||||||
|
SubRemLoadSubStatePreloaded,
|
||||||
|
SubRemLoadSubStateError,
|
||||||
|
SubRemLoadSubStateErrorIncorectPath,
|
||||||
|
SubRemLoadSubStateErrorNoFile,
|
||||||
|
SubRemLoadSubStateErrorFreq,
|
||||||
|
SubRemLoadSubStateErrorMod,
|
||||||
|
SubRemLoadSubStateErrorProtocol,
|
||||||
|
SubRemLoadSubStateOK,
|
||||||
|
} SubRemLoadSubState;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
SubRemLoadMapStateBack = 0,
|
||||||
|
SubRemLoadMapStateError,
|
||||||
|
SubRemLoadMapStateErrorOpenError,
|
||||||
|
SubRemLoadMapStateErrorStorage,
|
||||||
|
SubRemLoadMapStateErrorBrokenFile,
|
||||||
|
SubRemLoadMapStateNotAllOK,
|
||||||
|
SubRemLoadMapStateOK,
|
||||||
|
} SubRemLoadMapState;
|
||||||
4
applications/external/subghz_remote_configurator/helpers/txrx/Readme.md
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
This is part of the official `SubGhz` app from [flipperzero-firmware](https://github.com/flipperdevices/flipperzero-firmware/tree/3217f286f03da119398586daf94c0723d28b872a/applications/main/subghz)
|
||||||
|
|
||||||
|
With changes from [unleashed-firmware
|
||||||
|
](https://github.com/DarkFlippers/unleashed-firmware/tree/3eac6ccd48a3851cf5d63bf7899b387a293e5319/applications/main/subghz)
|
||||||
563
applications/external/subghz_remote_configurator/helpers/txrx/subghz_txrx.c
vendored
Normal file
@@ -0,0 +1,563 @@
|
|||||||
|
#include "subghz_txrx_i.h"
|
||||||
|
#include <lib/subghz/protocols/protocol_items.h>
|
||||||
|
|
||||||
|
#define TAG "SubGhz"
|
||||||
|
|
||||||
|
SubGhzTxRx* subghz_txrx_alloc() {
|
||||||
|
SubGhzTxRx* instance = malloc(sizeof(SubGhzTxRx));
|
||||||
|
instance->setting = subghz_setting_alloc();
|
||||||
|
subghz_setting_load(instance->setting, EXT_PATH("subghz/assets/setting_user"));
|
||||||
|
|
||||||
|
instance->preset = malloc(sizeof(SubGhzRadioPreset));
|
||||||
|
instance->preset->name = furi_string_alloc();
|
||||||
|
subghz_txrx_set_preset(
|
||||||
|
instance, "AM650", subghz_setting_get_default_frequency(instance->setting), NULL, 0);
|
||||||
|
|
||||||
|
instance->txrx_state = SubGhzTxRxStateSleep;
|
||||||
|
|
||||||
|
subghz_txrx_hopper_set_state(instance, SubGhzHopperStateOFF);
|
||||||
|
subghz_txrx_speaker_set_state(instance, SubGhzSpeakerStateDisable);
|
||||||
|
subghz_txrx_set_debug_pin_state(instance, false);
|
||||||
|
|
||||||
|
instance->worker = subghz_worker_alloc();
|
||||||
|
instance->fff_data = flipper_format_string_alloc();
|
||||||
|
|
||||||
|
instance->environment = subghz_environment_alloc();
|
||||||
|
instance->is_database_loaded = subghz_environment_load_keystore(
|
||||||
|
instance->environment, EXT_PATH("subghz/assets/keeloq_mfcodes"));
|
||||||
|
subghz_environment_load_keystore(
|
||||||
|
instance->environment, EXT_PATH("subghz/assets/keeloq_mfcodes_user"));
|
||||||
|
subghz_environment_set_came_atomo_rainbow_table_file_name(
|
||||||
|
instance->environment, EXT_PATH("subghz/assets/came_atomo"));
|
||||||
|
subghz_environment_set_alutech_at_4n_rainbow_table_file_name(
|
||||||
|
instance->environment, EXT_PATH("subghz/assets/alutech_at_4n"));
|
||||||
|
subghz_environment_set_nice_flor_s_rainbow_table_file_name(
|
||||||
|
instance->environment, EXT_PATH("subghz/assets/nice_flor_s"));
|
||||||
|
subghz_environment_set_protocol_registry(
|
||||||
|
instance->environment, (void*)&subghz_protocol_registry);
|
||||||
|
instance->receiver = subghz_receiver_alloc_init(instance->environment);
|
||||||
|
|
||||||
|
subghz_worker_set_overrun_callback(
|
||||||
|
instance->worker, (SubGhzWorkerOverrunCallback)subghz_receiver_reset);
|
||||||
|
subghz_worker_set_pair_callback(
|
||||||
|
instance->worker, (SubGhzWorkerPairCallback)subghz_receiver_decode);
|
||||||
|
subghz_worker_set_context(instance->worker, instance->receiver);
|
||||||
|
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
void subghz_txrx_free(SubGhzTxRx* instance) {
|
||||||
|
furi_assert(instance);
|
||||||
|
|
||||||
|
subghz_worker_free(instance->worker);
|
||||||
|
subghz_receiver_free(instance->receiver);
|
||||||
|
subghz_environment_free(instance->environment);
|
||||||
|
flipper_format_free(instance->fff_data);
|
||||||
|
furi_string_free(instance->preset->name);
|
||||||
|
subghz_setting_free(instance->setting);
|
||||||
|
free(instance->preset);
|
||||||
|
free(instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool subghz_txrx_is_database_loaded(SubGhzTxRx* instance) {
|
||||||
|
furi_assert(instance);
|
||||||
|
return instance->is_database_loaded;
|
||||||
|
}
|
||||||
|
|
||||||
|
void subghz_txrx_set_preset(
|
||||||
|
SubGhzTxRx* instance,
|
||||||
|
const char* preset_name,
|
||||||
|
uint32_t frequency,
|
||||||
|
uint8_t* preset_data,
|
||||||
|
size_t preset_data_size) {
|
||||||
|
furi_assert(instance);
|
||||||
|
furi_string_set(instance->preset->name, preset_name);
|
||||||
|
SubGhzRadioPreset* preset = instance->preset;
|
||||||
|
preset->frequency = frequency;
|
||||||
|
preset->data = preset_data;
|
||||||
|
preset->data_size = preset_data_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* subghz_txrx_get_preset_name(SubGhzTxRx* instance, const char* preset) {
|
||||||
|
UNUSED(instance);
|
||||||
|
const char* preset_name = "";
|
||||||
|
if(!strcmp(preset, "FuriHalSubGhzPresetOok270Async")) {
|
||||||
|
preset_name = "AM270";
|
||||||
|
} else if(!strcmp(preset, "FuriHalSubGhzPresetOok650Async")) {
|
||||||
|
preset_name = "AM650";
|
||||||
|
} else if(!strcmp(preset, "FuriHalSubGhzPreset2FSKDev238Async")) {
|
||||||
|
preset_name = "FM238";
|
||||||
|
} else if(!strcmp(preset, "FuriHalSubGhzPreset2FSKDev476Async")) {
|
||||||
|
preset_name = "FM476";
|
||||||
|
} else if(!strcmp(preset, "FuriHalSubGhzPresetCustom")) {
|
||||||
|
preset_name = "CUSTOM";
|
||||||
|
} else {
|
||||||
|
FURI_LOG_E(TAG, "Unknown preset");
|
||||||
|
}
|
||||||
|
return preset_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
SubGhzRadioPreset subghz_txrx_get_preset(SubGhzTxRx* instance) {
|
||||||
|
furi_assert(instance);
|
||||||
|
return *instance->preset;
|
||||||
|
}
|
||||||
|
|
||||||
|
void subghz_txrx_get_frequency_and_modulation(
|
||||||
|
SubGhzTxRx* instance,
|
||||||
|
FuriString* frequency,
|
||||||
|
FuriString* modulation,
|
||||||
|
bool long_name) {
|
||||||
|
furi_assert(instance);
|
||||||
|
SubGhzRadioPreset* preset = instance->preset;
|
||||||
|
if(frequency != NULL) {
|
||||||
|
furi_string_printf(
|
||||||
|
frequency,
|
||||||
|
"%03ld.%02ld",
|
||||||
|
preset->frequency / 1000000 % 1000,
|
||||||
|
preset->frequency / 10000 % 100);
|
||||||
|
}
|
||||||
|
if(modulation != NULL) {
|
||||||
|
if(long_name) {
|
||||||
|
furi_string_printf(modulation, "%s", furi_string_get_cstr(preset->name));
|
||||||
|
} else {
|
||||||
|
furi_string_printf(modulation, "%.2s", furi_string_get_cstr(preset->name));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void subghz_txrx_begin(SubGhzTxRx* instance, uint8_t* preset_data) {
|
||||||
|
furi_assert(instance);
|
||||||
|
furi_hal_subghz_reset();
|
||||||
|
furi_hal_subghz_idle();
|
||||||
|
furi_hal_subghz_load_custom_preset(preset_data);
|
||||||
|
furi_hal_gpio_init(furi_hal_subghz.cc1101_g0_pin, GpioModeInput, GpioPullNo, GpioSpeedLow);
|
||||||
|
instance->txrx_state = SubGhzTxRxStateIDLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint32_t subghz_txrx_rx(SubGhzTxRx* instance, uint32_t frequency) {
|
||||||
|
furi_assert(instance);
|
||||||
|
if(!furi_hal_subghz_is_frequency_valid(frequency)) {
|
||||||
|
furi_crash("SubGhz: Incorrect RX frequency.");
|
||||||
|
}
|
||||||
|
furi_assert(
|
||||||
|
instance->txrx_state != SubGhzTxRxStateRx && instance->txrx_state != SubGhzTxRxStateSleep);
|
||||||
|
|
||||||
|
furi_hal_subghz_idle();
|
||||||
|
uint32_t value = furi_hal_subghz_set_frequency_and_path(frequency);
|
||||||
|
furi_hal_gpio_init(furi_hal_subghz.cc1101_g0_pin, GpioModeInput, GpioPullNo, GpioSpeedLow);
|
||||||
|
furi_hal_subghz_flush_rx();
|
||||||
|
subghz_txrx_speaker_on(instance);
|
||||||
|
furi_hal_subghz_rx();
|
||||||
|
|
||||||
|
furi_hal_subghz_start_async_rx(subghz_worker_rx_callback, instance->worker);
|
||||||
|
subghz_worker_start(instance->worker);
|
||||||
|
instance->txrx_state = SubGhzTxRxStateRx;
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void subghz_txrx_idle(SubGhzTxRx* instance) {
|
||||||
|
furi_assert(instance);
|
||||||
|
furi_assert(instance->txrx_state != SubGhzTxRxStateSleep);
|
||||||
|
furi_hal_subghz_idle();
|
||||||
|
subghz_txrx_speaker_off(instance);
|
||||||
|
instance->txrx_state = SubGhzTxRxStateIDLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void subghz_txrx_rx_end(SubGhzTxRx* instance) {
|
||||||
|
furi_assert(instance);
|
||||||
|
furi_assert(instance->txrx_state == SubGhzTxRxStateRx);
|
||||||
|
|
||||||
|
if(subghz_worker_is_running(instance->worker)) {
|
||||||
|
subghz_worker_stop(instance->worker);
|
||||||
|
furi_hal_subghz_stop_async_rx();
|
||||||
|
}
|
||||||
|
furi_hal_subghz_idle();
|
||||||
|
subghz_txrx_speaker_off(instance);
|
||||||
|
instance->txrx_state = SubGhzTxRxStateIDLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void subghz_txrx_sleep(SubGhzTxRx* instance) {
|
||||||
|
furi_assert(instance);
|
||||||
|
furi_hal_subghz_sleep();
|
||||||
|
instance->txrx_state = SubGhzTxRxStateSleep;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool subghz_txrx_tx(SubGhzTxRx* instance, uint32_t frequency) {
|
||||||
|
furi_assert(instance);
|
||||||
|
if(!furi_hal_subghz_is_frequency_valid(frequency)) {
|
||||||
|
furi_crash("SubGhz: Incorrect TX frequency.");
|
||||||
|
}
|
||||||
|
furi_assert(instance->txrx_state != SubGhzTxRxStateSleep);
|
||||||
|
furi_hal_subghz_idle();
|
||||||
|
furi_hal_subghz_set_frequency_and_path(frequency);
|
||||||
|
furi_hal_gpio_write(furi_hal_subghz.cc1101_g0_pin, false);
|
||||||
|
furi_hal_gpio_init(
|
||||||
|
furi_hal_subghz.cc1101_g0_pin, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
|
||||||
|
bool ret = furi_hal_subghz_tx();
|
||||||
|
if(ret) {
|
||||||
|
subghz_txrx_speaker_on(instance);
|
||||||
|
instance->txrx_state = SubGhzTxRxStateTx;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
SubGhzTxRxStartTxState subghz_txrx_tx_start(SubGhzTxRx* instance, FlipperFormat* flipper_format) {
|
||||||
|
furi_assert(instance);
|
||||||
|
furi_assert(flipper_format);
|
||||||
|
|
||||||
|
subghz_txrx_stop(instance);
|
||||||
|
|
||||||
|
SubGhzTxRxStartTxState ret = SubGhzTxRxStartTxStateErrorParserOthers;
|
||||||
|
FuriString* temp_str = furi_string_alloc();
|
||||||
|
uint32_t repeat = 200;
|
||||||
|
do {
|
||||||
|
if(!flipper_format_rewind(flipper_format)) {
|
||||||
|
FURI_LOG_E(TAG, "Rewind error");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(!flipper_format_read_string(flipper_format, "Protocol", temp_str)) {
|
||||||
|
FURI_LOG_E(TAG, "Missing Protocol");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(!flipper_format_insert_or_update_uint32(flipper_format, "Repeat", &repeat, 1)) {
|
||||||
|
FURI_LOG_E(TAG, "Unable Repeat");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
ret = SubGhzTxRxStartTxStateOk;
|
||||||
|
|
||||||
|
SubGhzRadioPreset* preset = instance->preset;
|
||||||
|
instance->transmitter =
|
||||||
|
subghz_transmitter_alloc_init(instance->environment, furi_string_get_cstr(temp_str));
|
||||||
|
|
||||||
|
if(instance->transmitter) {
|
||||||
|
if(subghz_transmitter_deserialize(instance->transmitter, flipper_format) ==
|
||||||
|
SubGhzProtocolStatusOk) {
|
||||||
|
if(strcmp(furi_string_get_cstr(preset->name), "") != 0) {
|
||||||
|
subghz_txrx_begin(
|
||||||
|
instance,
|
||||||
|
subghz_setting_get_preset_data_by_name(
|
||||||
|
instance->setting, furi_string_get_cstr(preset->name)));
|
||||||
|
if(preset->frequency) {
|
||||||
|
if(!subghz_txrx_tx(instance, preset->frequency)) {
|
||||||
|
FURI_LOG_E(TAG, "Only Rx");
|
||||||
|
ret = SubGhzTxRxStartTxStateErrorOnlyRx;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ret = SubGhzTxRxStartTxStateErrorParserOthers;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
FURI_LOG_E(
|
||||||
|
TAG, "Unknown name preset \" %s \"", furi_string_get_cstr(preset->name));
|
||||||
|
ret = SubGhzTxRxStartTxStateErrorParserOthers;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(ret == SubGhzTxRxStartTxStateOk) {
|
||||||
|
//Start TX
|
||||||
|
furi_hal_subghz_start_async_tx(
|
||||||
|
subghz_transmitter_yield, instance->transmitter);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ret = SubGhzTxRxStartTxStateErrorParserOthers;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ret = SubGhzTxRxStartTxStateErrorParserOthers;
|
||||||
|
}
|
||||||
|
if(ret != SubGhzTxRxStartTxStateOk) {
|
||||||
|
subghz_transmitter_free(instance->transmitter);
|
||||||
|
if(instance->txrx_state != SubGhzTxRxStateIDLE) {
|
||||||
|
subghz_txrx_idle(instance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} while(false);
|
||||||
|
furi_string_free(temp_str);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
void subghz_txrx_rx_start(SubGhzTxRx* instance) {
|
||||||
|
furi_assert(instance);
|
||||||
|
subghz_txrx_stop(instance);
|
||||||
|
subghz_txrx_begin(
|
||||||
|
instance,
|
||||||
|
subghz_setting_get_preset_data_by_name(
|
||||||
|
subghz_txrx_get_setting(instance), furi_string_get_cstr(instance->preset->name)));
|
||||||
|
subghz_txrx_rx(instance, instance->preset->frequency);
|
||||||
|
}
|
||||||
|
|
||||||
|
void subghz_txrx_set_need_save_callback(
|
||||||
|
SubGhzTxRx* instance,
|
||||||
|
SubGhzTxRxNeedSaveCallback callback,
|
||||||
|
void* context) {
|
||||||
|
furi_assert(instance);
|
||||||
|
instance->need_save_callback = callback;
|
||||||
|
instance->need_save_context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void subghz_txrx_tx_stop(SubGhzTxRx* instance) {
|
||||||
|
furi_assert(instance);
|
||||||
|
furi_assert(instance->txrx_state == SubGhzTxRxStateTx);
|
||||||
|
//Stop TX
|
||||||
|
furi_hal_subghz_stop_async_tx();
|
||||||
|
subghz_transmitter_stop(instance->transmitter);
|
||||||
|
subghz_transmitter_free(instance->transmitter);
|
||||||
|
|
||||||
|
//if protocol dynamic then we save the last upload
|
||||||
|
if(instance->decoder_result->protocol->type == SubGhzProtocolTypeDynamic) {
|
||||||
|
if(instance->need_save_callback) {
|
||||||
|
instance->need_save_callback(instance->need_save_context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
subghz_txrx_idle(instance);
|
||||||
|
subghz_txrx_speaker_off(instance);
|
||||||
|
//Todo: Show message
|
||||||
|
// notification_message(notifications, &sequence_reset_red);
|
||||||
|
}
|
||||||
|
|
||||||
|
FlipperFormat* subghz_txrx_get_fff_data(SubGhzTxRx* instance) {
|
||||||
|
furi_assert(instance);
|
||||||
|
return instance->fff_data;
|
||||||
|
}
|
||||||
|
|
||||||
|
SubGhzSetting* subghz_txrx_get_setting(SubGhzTxRx* instance) {
|
||||||
|
furi_assert(instance);
|
||||||
|
return instance->setting;
|
||||||
|
}
|
||||||
|
|
||||||
|
void subghz_txrx_stop(SubGhzTxRx* instance) {
|
||||||
|
furi_assert(instance);
|
||||||
|
|
||||||
|
switch(instance->txrx_state) {
|
||||||
|
case SubGhzTxRxStateTx:
|
||||||
|
subghz_txrx_tx_stop(instance);
|
||||||
|
subghz_txrx_speaker_unmute(instance);
|
||||||
|
break;
|
||||||
|
case SubGhzTxRxStateRx:
|
||||||
|
subghz_txrx_rx_end(instance);
|
||||||
|
subghz_txrx_speaker_mute(instance);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void subghz_txrx_hopper_update(SubGhzTxRx* instance) {
|
||||||
|
furi_assert(instance);
|
||||||
|
|
||||||
|
switch(instance->hopper_state) {
|
||||||
|
case SubGhzHopperStateOFF:
|
||||||
|
case SubGhzHopperStatePause:
|
||||||
|
return;
|
||||||
|
case SubGhzHopperStateRSSITimeOut:
|
||||||
|
if(instance->hopper_timeout != 0) {
|
||||||
|
instance->hopper_timeout--;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
float rssi = -127.0f;
|
||||||
|
if(instance->hopper_state != SubGhzHopperStateRSSITimeOut) {
|
||||||
|
// See RSSI Calculation timings in CC1101 17.3 RSSI
|
||||||
|
rssi = furi_hal_subghz_get_rssi();
|
||||||
|
|
||||||
|
// Stay if RSSI is high enough
|
||||||
|
if(rssi > -90.0f) {
|
||||||
|
instance->hopper_timeout = 10;
|
||||||
|
instance->hopper_state = SubGhzHopperStateRSSITimeOut;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
instance->hopper_state = SubGhzHopperStateRunning;
|
||||||
|
}
|
||||||
|
// Select next frequency
|
||||||
|
if(instance->hopper_idx_frequency <
|
||||||
|
subghz_setting_get_hopper_frequency_count(instance->setting) - 1) {
|
||||||
|
instance->hopper_idx_frequency++;
|
||||||
|
} else {
|
||||||
|
instance->hopper_idx_frequency = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(instance->txrx_state == SubGhzTxRxStateRx) {
|
||||||
|
subghz_txrx_rx_end(instance);
|
||||||
|
};
|
||||||
|
if(instance->txrx_state == SubGhzTxRxStateIDLE) {
|
||||||
|
subghz_receiver_reset(instance->receiver);
|
||||||
|
instance->preset->frequency =
|
||||||
|
subghz_setting_get_hopper_frequency(instance->setting, instance->hopper_idx_frequency);
|
||||||
|
subghz_txrx_rx(instance, instance->preset->frequency);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SubGhzHopperState subghz_txrx_hopper_get_state(SubGhzTxRx* instance) {
|
||||||
|
furi_assert(instance);
|
||||||
|
return instance->hopper_state;
|
||||||
|
}
|
||||||
|
|
||||||
|
void subghz_txrx_hopper_set_state(SubGhzTxRx* instance, SubGhzHopperState state) {
|
||||||
|
furi_assert(instance);
|
||||||
|
instance->hopper_state = state;
|
||||||
|
}
|
||||||
|
|
||||||
|
void subghz_txrx_hopper_unpause(SubGhzTxRx* instance) {
|
||||||
|
furi_assert(instance);
|
||||||
|
if(instance->hopper_state == SubGhzHopperStatePause) {
|
||||||
|
instance->hopper_state = SubGhzHopperStateRunning;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void subghz_txrx_hopper_pause(SubGhzTxRx* instance) {
|
||||||
|
furi_assert(instance);
|
||||||
|
if(instance->hopper_state == SubGhzHopperStateRunning) {
|
||||||
|
instance->hopper_state = SubGhzHopperStatePause;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void subghz_txrx_speaker_on(SubGhzTxRx* instance) {
|
||||||
|
furi_assert(instance);
|
||||||
|
if(instance->debug_pin_state) {
|
||||||
|
furi_hal_subghz_set_async_mirror_pin(&gpio_ibutton);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(instance->speaker_state == SubGhzSpeakerStateEnable) {
|
||||||
|
if(furi_hal_speaker_acquire(30)) {
|
||||||
|
if(!instance->debug_pin_state) {
|
||||||
|
furi_hal_subghz_set_async_mirror_pin(&gpio_speaker);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
instance->speaker_state = SubGhzSpeakerStateDisable;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void subghz_txrx_speaker_off(SubGhzTxRx* instance) {
|
||||||
|
furi_assert(instance);
|
||||||
|
if(instance->debug_pin_state) {
|
||||||
|
furi_hal_subghz_set_async_mirror_pin(NULL);
|
||||||
|
}
|
||||||
|
if(instance->speaker_state != SubGhzSpeakerStateDisable) {
|
||||||
|
if(furi_hal_speaker_is_mine()) {
|
||||||
|
if(!instance->debug_pin_state) {
|
||||||
|
furi_hal_subghz_set_async_mirror_pin(NULL);
|
||||||
|
}
|
||||||
|
furi_hal_speaker_release();
|
||||||
|
if(instance->speaker_state == SubGhzSpeakerStateShutdown)
|
||||||
|
instance->speaker_state = SubGhzSpeakerStateDisable;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void subghz_txrx_speaker_mute(SubGhzTxRx* instance) {
|
||||||
|
furi_assert(instance);
|
||||||
|
if(instance->debug_pin_state) {
|
||||||
|
furi_hal_subghz_set_async_mirror_pin(NULL);
|
||||||
|
}
|
||||||
|
if(instance->speaker_state == SubGhzSpeakerStateEnable) {
|
||||||
|
if(furi_hal_speaker_is_mine()) {
|
||||||
|
if(!instance->debug_pin_state) {
|
||||||
|
furi_hal_subghz_set_async_mirror_pin(NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void subghz_txrx_speaker_unmute(SubGhzTxRx* instance) {
|
||||||
|
furi_assert(instance);
|
||||||
|
if(instance->debug_pin_state) {
|
||||||
|
furi_hal_subghz_set_async_mirror_pin(&gpio_ibutton);
|
||||||
|
}
|
||||||
|
if(instance->speaker_state == SubGhzSpeakerStateEnable) {
|
||||||
|
if(furi_hal_speaker_is_mine()) {
|
||||||
|
if(!instance->debug_pin_state) {
|
||||||
|
furi_hal_subghz_set_async_mirror_pin(&gpio_speaker);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void subghz_txrx_speaker_set_state(SubGhzTxRx* instance, SubGhzSpeakerState state) {
|
||||||
|
furi_assert(instance);
|
||||||
|
instance->speaker_state = state;
|
||||||
|
}
|
||||||
|
|
||||||
|
SubGhzSpeakerState subghz_txrx_speaker_get_state(SubGhzTxRx* instance) {
|
||||||
|
furi_assert(instance);
|
||||||
|
return instance->speaker_state;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool subghz_txrx_load_decoder_by_name_protocol(SubGhzTxRx* instance, const char* name_protocol) {
|
||||||
|
furi_assert(instance);
|
||||||
|
furi_assert(name_protocol);
|
||||||
|
bool res = false;
|
||||||
|
instance->decoder_result =
|
||||||
|
subghz_receiver_search_decoder_base_by_name(instance->receiver, name_protocol);
|
||||||
|
if(instance->decoder_result) {
|
||||||
|
res = true;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
SubGhzProtocolDecoderBase* subghz_txrx_get_decoder(SubGhzTxRx* instance) {
|
||||||
|
furi_assert(instance);
|
||||||
|
return instance->decoder_result;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool subghz_txrx_protocol_is_serializable(SubGhzTxRx* instance) {
|
||||||
|
furi_assert(instance);
|
||||||
|
return (
|
||||||
|
(instance->decoder_result->protocol->flag & SubGhzProtocolFlag_Save) ==
|
||||||
|
SubGhzProtocolFlag_Save);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool subghz_txrx_protocol_is_transmittable(SubGhzTxRx* instance, bool check_type) {
|
||||||
|
furi_assert(instance);
|
||||||
|
const SubGhzProtocol* protocol = instance->decoder_result->protocol;
|
||||||
|
if(check_type) {
|
||||||
|
return (
|
||||||
|
((protocol->flag & SubGhzProtocolFlag_Send) == SubGhzProtocolFlag_Send) &&
|
||||||
|
protocol->encoder->deserialize && protocol->type == SubGhzProtocolTypeStatic);
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
((protocol->flag & SubGhzProtocolFlag_Send) == SubGhzProtocolFlag_Send) &&
|
||||||
|
protocol->encoder->deserialize);
|
||||||
|
}
|
||||||
|
|
||||||
|
void subghz_txrx_receiver_set_filter(SubGhzTxRx* instance, SubGhzProtocolFlag filter) {
|
||||||
|
furi_assert(instance);
|
||||||
|
subghz_receiver_set_filter(instance->receiver, filter);
|
||||||
|
}
|
||||||
|
|
||||||
|
void subghz_txrx_set_rx_calback(
|
||||||
|
SubGhzTxRx* instance,
|
||||||
|
SubGhzReceiverCallback callback,
|
||||||
|
void* context) {
|
||||||
|
subghz_receiver_set_rx_callback(instance->receiver, callback, context);
|
||||||
|
}
|
||||||
|
|
||||||
|
void subghz_txrx_set_raw_file_encoder_worker_callback_end(
|
||||||
|
SubGhzTxRx* instance,
|
||||||
|
SubGhzProtocolEncoderRAWCallbackEnd callback,
|
||||||
|
void* context) {
|
||||||
|
subghz_protocol_raw_file_encoder_worker_set_callback_end(
|
||||||
|
(SubGhzProtocolEncoderRAW*)subghz_transmitter_get_protocol_instance(instance->transmitter),
|
||||||
|
callback,
|
||||||
|
context);
|
||||||
|
}
|
||||||
|
|
||||||
|
void subghz_txrx_set_debug_pin_state(SubGhzTxRx* instance, bool state) {
|
||||||
|
furi_assert(instance);
|
||||||
|
instance->debug_pin_state = state;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool subghz_txrx_get_debug_pin_state(SubGhzTxRx* instance) {
|
||||||
|
furi_assert(instance);
|
||||||
|
return instance->debug_pin_state;
|
||||||
|
}
|
||||||
|
|
||||||
|
SubGhzReceiver* subghz_txrx_get_receiver(SubGhzTxRx* instance) {
|
||||||
|
furi_assert(instance);
|
||||||
|
return instance->receiver;
|
||||||
|
}
|
||||||
318
applications/external/subghz_remote_configurator/helpers/txrx/subghz_txrx.h
vendored
Normal file
@@ -0,0 +1,318 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <lib/subghz/subghz_worker.h>
|
||||||
|
#include <lib/subghz/subghz_setting.h>
|
||||||
|
#include <lib/subghz/receiver.h>
|
||||||
|
#include <lib/subghz/transmitter.h>
|
||||||
|
#include <lib/subghz/protocols/raw.h>
|
||||||
|
|
||||||
|
typedef struct SubGhzTxRx SubGhzTxRx;
|
||||||
|
|
||||||
|
typedef void (*SubGhzTxRxNeedSaveCallback)(void* context);
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
SubGhzTxRxStartTxStateOk,
|
||||||
|
SubGhzTxRxStartTxStateErrorOnlyRx,
|
||||||
|
SubGhzTxRxStartTxStateErrorParserOthers,
|
||||||
|
} SubGhzTxRxStartTxState;
|
||||||
|
|
||||||
|
// Type from subghz_types.h need for txrx working
|
||||||
|
/** SubGhzTxRx state */
|
||||||
|
typedef enum {
|
||||||
|
SubGhzTxRxStateIDLE,
|
||||||
|
SubGhzTxRxStateRx,
|
||||||
|
SubGhzTxRxStateTx,
|
||||||
|
SubGhzTxRxStateSleep,
|
||||||
|
} SubGhzTxRxState;
|
||||||
|
|
||||||
|
/** SubGhzHopperState state */
|
||||||
|
typedef enum {
|
||||||
|
SubGhzHopperStateOFF,
|
||||||
|
SubGhzHopperStateRunning,
|
||||||
|
SubGhzHopperStatePause,
|
||||||
|
SubGhzHopperStateRSSITimeOut,
|
||||||
|
} SubGhzHopperState;
|
||||||
|
|
||||||
|
/** SubGhzSpeakerState state */
|
||||||
|
typedef enum {
|
||||||
|
SubGhzSpeakerStateDisable,
|
||||||
|
SubGhzSpeakerStateShutdown,
|
||||||
|
SubGhzSpeakerStateEnable,
|
||||||
|
} SubGhzSpeakerState;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allocate SubGhzTxRx
|
||||||
|
*
|
||||||
|
* @return SubGhzTxRx* pointer to SubGhzTxRx
|
||||||
|
*/
|
||||||
|
SubGhzTxRx* subghz_txrx_alloc();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Free SubGhzTxRx
|
||||||
|
*
|
||||||
|
* @param instance Pointer to a SubGhzTxRx
|
||||||
|
*/
|
||||||
|
void subghz_txrx_free(SubGhzTxRx* instance);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the database is loaded
|
||||||
|
*
|
||||||
|
* @param instance Pointer to a SubGhzTxRx
|
||||||
|
* @return bool True if the database is loaded
|
||||||
|
*/
|
||||||
|
bool subghz_txrx_is_database_loaded(SubGhzTxRx* instance);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set preset
|
||||||
|
*
|
||||||
|
* @param instance Pointer to a SubGhzTxRx
|
||||||
|
* @param preset_name Name of preset
|
||||||
|
* @param frequency Frequency in Hz
|
||||||
|
* @param preset_data Data of preset
|
||||||
|
* @param preset_data_size Size of preset data
|
||||||
|
*/
|
||||||
|
void subghz_txrx_set_preset(
|
||||||
|
SubGhzTxRx* instance,
|
||||||
|
const char* preset_name,
|
||||||
|
uint32_t frequency,
|
||||||
|
uint8_t* preset_data,
|
||||||
|
size_t preset_data_size);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get name of preset
|
||||||
|
*
|
||||||
|
* @param instance Pointer to a SubGhzTxRx
|
||||||
|
* @param preset String of preset
|
||||||
|
* @return const char* Name of preset
|
||||||
|
*/
|
||||||
|
const char* subghz_txrx_get_preset_name(SubGhzTxRx* instance, const char* preset);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get of preset
|
||||||
|
*
|
||||||
|
* @param instance Pointer to a SubGhzTxRx
|
||||||
|
* @return SubGhzRadioPreset Preset
|
||||||
|
*/
|
||||||
|
SubGhzRadioPreset subghz_txrx_get_preset(SubGhzTxRx* instance);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get string frequency and modulation
|
||||||
|
*
|
||||||
|
* @param instance Pointer to a SubGhzTxRx
|
||||||
|
* @param frequency Pointer to a string frequency
|
||||||
|
* @param modulation Pointer to a string modulation
|
||||||
|
*/
|
||||||
|
void subghz_txrx_get_frequency_and_modulation(
|
||||||
|
SubGhzTxRx* instance,
|
||||||
|
FuriString* frequency,
|
||||||
|
FuriString* modulation,
|
||||||
|
bool long_name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start TX CC1101
|
||||||
|
*
|
||||||
|
* @param instance Pointer to a SubGhzTxRx
|
||||||
|
* @param flipper_format Pointer to a FlipperFormat
|
||||||
|
* @return SubGhzTxRxStartTxState
|
||||||
|
*/
|
||||||
|
SubGhzTxRxStartTxState subghz_txrx_tx_start(SubGhzTxRx* instance, FlipperFormat* flipper_format);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start RX CC1101
|
||||||
|
*
|
||||||
|
* @param instance Pointer to a SubGhzTxRx
|
||||||
|
*/
|
||||||
|
void subghz_txrx_rx_start(SubGhzTxRx* instance);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stop TX/RX CC1101
|
||||||
|
*
|
||||||
|
* @param instance Pointer to a SubGhzTxRx
|
||||||
|
*/
|
||||||
|
void subghz_txrx_stop(SubGhzTxRx* instance);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set sleep mode CC1101
|
||||||
|
*
|
||||||
|
* @param instance Pointer to a SubGhzTxRx
|
||||||
|
*/
|
||||||
|
void subghz_txrx_sleep(SubGhzTxRx* instance);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update frequency CC1101 in automatic mode (hopper)
|
||||||
|
*
|
||||||
|
* @param instance Pointer to a SubGhzTxRx
|
||||||
|
*/
|
||||||
|
void subghz_txrx_hopper_update(SubGhzTxRx* instance);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get state hopper
|
||||||
|
*
|
||||||
|
* @param instance Pointer to a SubGhzTxRx
|
||||||
|
* @return SubGhzHopperState
|
||||||
|
*/
|
||||||
|
SubGhzHopperState subghz_txrx_hopper_get_state(SubGhzTxRx* instance);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set state hopper
|
||||||
|
*
|
||||||
|
* @param instance Pointer to a SubGhzTxRx
|
||||||
|
* @param state State hopper
|
||||||
|
*/
|
||||||
|
void subghz_txrx_hopper_set_state(SubGhzTxRx* instance, SubGhzHopperState state);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unpause hopper
|
||||||
|
*
|
||||||
|
* @param instance Pointer to a SubGhzTxRx
|
||||||
|
*/
|
||||||
|
void subghz_txrx_hopper_unpause(SubGhzTxRx* instance);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set pause hopper
|
||||||
|
*
|
||||||
|
* @param instance Pointer to a SubGhzTxRx
|
||||||
|
*/
|
||||||
|
void subghz_txrx_hopper_pause(SubGhzTxRx* instance);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Speaker on
|
||||||
|
*
|
||||||
|
* @param instance Pointer to a SubGhzTxRx
|
||||||
|
*/
|
||||||
|
void subghz_txrx_speaker_on(SubGhzTxRx* instance);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Speaker off
|
||||||
|
*
|
||||||
|
* @param instance Pointer to a SubGhzTxRx
|
||||||
|
*/
|
||||||
|
void subghz_txrx_speaker_off(SubGhzTxRx* instance);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Speaker mute
|
||||||
|
*
|
||||||
|
* @param instance Pointer to a SubGhzTxRx
|
||||||
|
*/
|
||||||
|
void subghz_txrx_speaker_mute(SubGhzTxRx* instance);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Speaker unmute
|
||||||
|
*
|
||||||
|
* @param instance Pointer to a SubGhzTxRx
|
||||||
|
*/
|
||||||
|
void subghz_txrx_speaker_unmute(SubGhzTxRx* instance);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set state speaker
|
||||||
|
*
|
||||||
|
* @param instance Pointer to a SubGhzTxRx
|
||||||
|
* @param state State speaker
|
||||||
|
*/
|
||||||
|
void subghz_txrx_speaker_set_state(SubGhzTxRx* instance, SubGhzSpeakerState state);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get state speaker
|
||||||
|
*
|
||||||
|
* @param instance Pointer to a SubGhzTxRx
|
||||||
|
* @return SubGhzSpeakerState
|
||||||
|
*/
|
||||||
|
SubGhzSpeakerState subghz_txrx_speaker_get_state(SubGhzTxRx* instance);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* load decoder by name protocol
|
||||||
|
*
|
||||||
|
* @param instance Pointer to a SubGhzTxRx
|
||||||
|
* @param name_protocol Name protocol
|
||||||
|
* @return bool True if the decoder is loaded
|
||||||
|
*/
|
||||||
|
bool subghz_txrx_load_decoder_by_name_protocol(SubGhzTxRx* instance, const char* name_protocol);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get decoder
|
||||||
|
*
|
||||||
|
* @param instance Pointer to a SubGhzTxRx
|
||||||
|
* @return SubGhzProtocolDecoderBase* Pointer to a SubGhzProtocolDecoderBase
|
||||||
|
*/
|
||||||
|
SubGhzProtocolDecoderBase* subghz_txrx_get_decoder(SubGhzTxRx* instance);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set callback for save data
|
||||||
|
*
|
||||||
|
* @param instance Pointer to a SubGhzTxRx
|
||||||
|
* @param callback Callback for save data
|
||||||
|
* @param context Context for callback
|
||||||
|
*/
|
||||||
|
void subghz_txrx_set_need_save_callback(
|
||||||
|
SubGhzTxRx* instance,
|
||||||
|
SubGhzTxRxNeedSaveCallback callback,
|
||||||
|
void* context);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get pointer to a load data key
|
||||||
|
*
|
||||||
|
* @param instance Pointer to a SubGhzTxRx
|
||||||
|
* @return FlipperFormat*
|
||||||
|
*/
|
||||||
|
FlipperFormat* subghz_txrx_get_fff_data(SubGhzTxRx* instance);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get pointer to a SugGhzSetting
|
||||||
|
*
|
||||||
|
* @param instance Pointer to a SubGhzTxRx
|
||||||
|
* @return SubGhzSetting*
|
||||||
|
*/
|
||||||
|
SubGhzSetting* subghz_txrx_get_setting(SubGhzTxRx* instance);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is it possible to save this protocol
|
||||||
|
*
|
||||||
|
* @param instance Pointer to a SubGhzTxRx
|
||||||
|
* @return bool True if it is possible to save this protocol
|
||||||
|
*/
|
||||||
|
bool subghz_txrx_protocol_is_serializable(SubGhzTxRx* instance);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is it possible to send this protocol
|
||||||
|
*
|
||||||
|
* @param instance Pointer to a SubGhzTxRx
|
||||||
|
* @return bool True if it is possible to send this protocol
|
||||||
|
*/
|
||||||
|
bool subghz_txrx_protocol_is_transmittable(SubGhzTxRx* instance, bool check_type);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set filter, what types of decoder to use
|
||||||
|
*
|
||||||
|
* @param instance Pointer to a SubGhzTxRx
|
||||||
|
* @param filter Filter
|
||||||
|
*/
|
||||||
|
void subghz_txrx_receiver_set_filter(SubGhzTxRx* instance, SubGhzProtocolFlag filter);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set callback for receive data
|
||||||
|
*
|
||||||
|
* @param instance Pointer to a SubGhzTxRx
|
||||||
|
* @param callback Callback for receive data
|
||||||
|
* @param context Context for callback
|
||||||
|
*/
|
||||||
|
void subghz_txrx_set_rx_calback(
|
||||||
|
SubGhzTxRx* instance,
|
||||||
|
SubGhzReceiverCallback callback,
|
||||||
|
void* context);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set callback for Raw decoder, end of data transfer
|
||||||
|
*
|
||||||
|
* @param instance Pointer to a SubGhzTxRx
|
||||||
|
* @param callback Callback for Raw decoder, end of data transfer
|
||||||
|
* @param context Context for callback
|
||||||
|
*/
|
||||||
|
void subghz_txrx_set_raw_file_encoder_worker_callback_end(
|
||||||
|
SubGhzTxRx* instance,
|
||||||
|
SubGhzProtocolEncoderRAWCallbackEnd callback,
|
||||||
|
void* context);
|
||||||
|
|
||||||
|
void subghz_txrx_set_debug_pin_state(SubGhzTxRx* instance, bool state);
|
||||||
|
bool subghz_txrx_get_debug_pin_state(SubGhzTxRx* instance);
|
||||||
|
|
||||||
|
SubGhzReceiver* subghz_txrx_get_receiver(SubGhzTxRx* instance); // TODO use only in DecodeRaw
|
||||||
29
applications/external/subghz_remote_configurator/helpers/txrx/subghz_txrx_i.h
vendored
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "subghz_txrx.h"
|
||||||
|
|
||||||
|
struct SubGhzTxRx {
|
||||||
|
SubGhzWorker* worker;
|
||||||
|
|
||||||
|
SubGhzEnvironment* environment;
|
||||||
|
SubGhzReceiver* receiver;
|
||||||
|
SubGhzTransmitter* transmitter;
|
||||||
|
SubGhzProtocolDecoderBase* decoder_result;
|
||||||
|
FlipperFormat* fff_data;
|
||||||
|
|
||||||
|
SubGhzRadioPreset* preset;
|
||||||
|
SubGhzSetting* setting;
|
||||||
|
|
||||||
|
uint8_t hopper_timeout;
|
||||||
|
uint8_t hopper_idx_frequency;
|
||||||
|
bool is_database_loaded;
|
||||||
|
SubGhzHopperState hopper_state;
|
||||||
|
|
||||||
|
SubGhzTxRxState txrx_state;
|
||||||
|
SubGhzSpeakerState speaker_state;
|
||||||
|
|
||||||
|
SubGhzTxRxNeedSaveCallback need_save_callback;
|
||||||
|
void* need_save_context;
|
||||||
|
|
||||||
|
bool debug_pin_state;
|
||||||
|
};
|
||||||
BIN
applications/external/subghz_remote_configurator/icons/DolphinNice_96x59.png
vendored
Normal file
|
After Width: | Height: | Size: 2.4 KiB |
BIN
applications/external/subghz_remote_configurator/icons/remote_scene/ButtonDown_7x4.png
vendored
Normal file
|
After Width: | Height: | Size: 102 B |
BIN
applications/external/subghz_remote_configurator/icons/remote_scene/ButtonLeft_4x7.png
vendored
Normal file
|
After Width: | Height: | Size: 1.4 KiB |
BIN
applications/external/subghz_remote_configurator/icons/remote_scene/ButtonRight_4x7.png
vendored
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
applications/external/subghz_remote_configurator/icons/remote_scene/ButtonUp_7x4.png
vendored
Normal file
|
After Width: | Height: | Size: 102 B |
BIN
applications/external/subghz_remote_configurator/icons/remote_scene/Ok_btn_9x9.png
vendored
Normal file
|
After Width: | Height: | Size: 3.5 KiB |
BIN
applications/external/subghz_remote_configurator/icons/remote_scene/Pin_arrow_up_7x9.png
vendored
Normal file
|
After Width: | Height: | Size: 3.5 KiB |
BIN
applications/external/subghz_remote_configurator/icons/remote_scene/Pin_cell_13x13.png
vendored
Normal file
|
After Width: | Height: | Size: 3.5 KiB |