Skip to content

Commit

Permalink
1.1.1 - Improve calibration cycle (hope nothing breaks)
Browse files Browse the repository at this point in the history
  • Loading branch information
AloneLiberty committed Apr 16, 2023
1 parent f7991cb commit c9654ab
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ A: By nonces I mean authorization attempts on the tag. Because we can predict PR

Q: How I can ask for help?

A: Create issue **with label "Question"** or use [discussions](https://github.com/AloneLiberty/FlipperNested/discussions). If you can't share private info in issue you can contact me in [Telegram](https://t.me/liberydev).
A: Create issue **with label "Question"** or use [discussions](https://github.com/AloneLiberty/FlipperNested/discussions). If you can't share private info in issue you can contact me in [Telegram](https://t.me/libertydev).

Q: What is being done at the moment and what are the plans?

Expand Down
24 changes: 20 additions & 4 deletions lib/nested/nested.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,16 +297,21 @@ uint32_t nested_calibrate_distance(
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;

mifare_classic_authex(crypto, tx_rx, cuid, blockNo, keyType, ui64Key, false, &nt1);
if(!mifare_classic_authex(crypto, tx_rx, cuid, blockNo, keyType, ui64Key, false, &nt1)) {
continue;
}

furi_delay_us(delay);

mifare_classic_authex(crypto, tx_rx, cuid, blockNo, keyType, ui64Key, true, &nt2);
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);
Expand All @@ -321,9 +326,12 @@ uint32_t nested_calibrate_distance(
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) {
Expand All @@ -335,10 +343,18 @@ uint32_t nested_calibrate_distance(
}
}

if(rtr > 1) davg = (davg + (rtr - 1) / 2) / (rtr - 1);
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", rtr, dmin, dmax, davg);
TAG,
"Calibration completed: rtr=%lu min=%lu max=%lu avg=%lu collected=%lu",
rtr,
dmin,
dmax,
davg,
collected);

nfc_deactivate();

Expand Down
2 changes: 1 addition & 1 deletion mifare_nested_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <lib/nfc/nfc_device.h>
#include "mifare_nested_icons.h"

#define NESTED_VERSION_APP "1.1.0"
#define NESTED_VERSION_APP "1.1.1"
#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 "2"
Expand Down

0 comments on commit c9654ab

Please sign in to comment.