Skip to content

Commit

Permalink
Merge branch 'flipperdevices:dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Z3BRO authored Apr 19, 2024
2 parents 92e7245 + c876835 commit c8ad76a
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 73 deletions.
70 changes: 35 additions & 35 deletions applications/main/nfc/api/mosgortrans/mosgortrans_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ bool mosgortrans_parse_transport_block(const MfClassicBlock* block, FuriString*
card_use_before_date_s.year);

if(data_block.valid_from_date == 0 || data_block.valid_to_date == 0) {
furi_string_cat(result, "\e#No ticket\n");
furi_string_cat(result, "\e#No ticket");
return true;
}
//remaining_trips
Expand Down Expand Up @@ -625,7 +625,7 @@ bool mosgortrans_parse_transport_block(const MfClassicBlock* block, FuriString*
data_block.valid_from_date + data_block.valid_for_days, &card_valid_to_date_s, 1992);
furi_string_cat_printf(
result,
"Valid to: %02d.%02d.%04d\n",
"Valid to: %02d.%02d.%04d",
card_valid_to_date_s.day,
card_valid_to_date_s.month,
card_valid_to_date_s.year);
Expand Down Expand Up @@ -663,7 +663,7 @@ bool mosgortrans_parse_transport_block(const MfClassicBlock* block, FuriString*
2016);
furi_string_cat_printf(
result,
"Valid to: %02d.%02d.%04d\n",
"Valid to: %02d.%02d.%04d",
card_valid_to_date_s.day,
card_valid_to_date_s.month,
card_valid_to_date_s.year);
Expand All @@ -676,7 +676,7 @@ bool mosgortrans_parse_transport_block(const MfClassicBlock* block, FuriString*
2016);
furi_string_cat_printf(
result,
"Trip from: %02d.%02d.%04d %02d:%02d\n",
"\nTrip from: %02d.%02d.%04d %02d:%02d",
card_start_trip_minutes_s.day,
card_start_trip_minutes_s.month,
card_start_trip_minutes_s.year,
Expand All @@ -693,7 +693,7 @@ bool mosgortrans_parse_transport_block(const MfClassicBlock* block, FuriString*
2016);
furi_string_cat_printf(
result,
"Trip switch: %02d.%02d.%04d %02d:%02d\n",
"\nTrip switch: %02d.%02d.%04d %02d:%02d",
card_start_switch_trip_minutes_s.day,
card_start_switch_trip_minutes_s.month,
card_start_switch_trip_minutes_s.year,
Expand All @@ -703,10 +703,10 @@ bool mosgortrans_parse_transport_block(const MfClassicBlock* block, FuriString*
//transport
FuriString* transport = furi_string_alloc();
parse_transport_type(&data_block, transport);
furi_string_cat_printf(result, "Transport: %s\n", furi_string_get_cstr(transport));
furi_string_cat_printf(result, "\nTransport: %s", furi_string_get_cstr(transport));
//validator
if(data_block.validator) {
furi_string_cat_printf(result, "Validator: %05d\n", data_block.validator);
furi_string_cat_printf(result, "\nValidator: %05d", data_block.validator);
}
furi_string_free(transport);
break;
Expand Down Expand Up @@ -740,9 +740,9 @@ bool mosgortrans_parse_transport_block(const MfClassicBlock* block, FuriString*
card_valid_to_date_s.month,
card_valid_to_date_s.year);
//remaining_trips
furi_string_cat_printf(result, "Trips left: %d\n", data_block.remaining_trips);
furi_string_cat_printf(result, "Trips left: %d", data_block.remaining_trips);
//trip_from
if(data_block.start_trip_date) {
if(data_block.start_trip_date) { // TODO: (-nofl) unused
DateTime card_start_trip_minutes_s = {0};
from_minutes_to_datetime(
data_block.start_trip_date * 24 * 60 + data_block.start_trip_time,
Expand All @@ -751,7 +751,7 @@ bool mosgortrans_parse_transport_block(const MfClassicBlock* block, FuriString*
}
//validator
if(data_block.validator) {
furi_string_cat_printf(result, "Validator: %05d", data_block.validator);
furi_string_cat_printf(result, "\nValidator: %05d", data_block.validator);
}
break;
}
Expand Down Expand Up @@ -785,20 +785,20 @@ bool mosgortrans_parse_transport_block(const MfClassicBlock* block, FuriString*
data_block.valid_from_date + data_block.valid_for_days, &card_valid_to_date_s, 1992);
furi_string_cat_printf(
result,
"Valid to: %02d.%02d.%04d\n",
"Valid to: %02d.%02d.%04d",
card_valid_to_date_s.day,
card_valid_to_date_s.month,
card_valid_to_date_s.year);
//trip_from
if(data_block.start_trip_date) {
if(data_block.start_trip_date) { // TODO: (-nofl) unused
DateTime card_start_trip_minutes_s = {0};
from_minutes_to_datetime(
data_block.start_trip_date * 24 * 60 + data_block.start_trip_time,
&card_start_trip_minutes_s,
1992);
}
//trip_switch
if(data_block.passage_5_minutes) {
if(data_block.passage_5_minutes) { // TODO: (-nofl) unused
DateTime card_start_switch_trip_minutes_s = {0};
from_minutes_to_datetime(
data_block.start_trip_date * 24 * 60 + data_block.start_trip_time +
Expand All @@ -808,7 +808,7 @@ bool mosgortrans_parse_transport_block(const MfClassicBlock* block, FuriString*
}
//validator
if(data_block.validator) {
furi_string_cat_printf(result, "Validator: %05d", data_block.validator);
furi_string_cat_printf(result, "\nValidator: %05d", data_block.validator);
}
break;
}
Expand Down Expand Up @@ -870,10 +870,10 @@ bool mosgortrans_parse_transport_block(const MfClassicBlock* block, FuriString*
furi_string_cat(transport, "");
break;
}
furi_string_cat_printf(result, "Transport: %s\n", furi_string_get_cstr(transport));
furi_string_cat_printf(result, "Transport: %s", furi_string_get_cstr(transport));
//validator
if(data_block.validator) {
furi_string_cat_printf(result, "Validator: %05d", data_block.validator);
furi_string_cat_printf(result, "\nValidator: %05d", data_block.validator);
}
furi_string_free(transport);
break;
Expand All @@ -899,7 +899,7 @@ bool mosgortrans_parse_transport_block(const MfClassicBlock* block, FuriString*
from_days_to_datetime(data_block.valid_from_date, &card_valid_from_date_s, 1992);
furi_string_cat_printf(
result,
"Valid from: %02d.%02d.%04d\n",
"Valid from: %02d.%02d.%04d",
card_valid_from_date_s.day,
card_valid_from_date_s.month,
card_valid_from_date_s.year);
Expand All @@ -912,7 +912,7 @@ bool mosgortrans_parse_transport_block(const MfClassicBlock* block, FuriString*
1992);
furi_string_cat_printf(
result,
"Valid to: %02d.%02d.%04d\n",
"\nValid to: %02d.%02d.%04d",
card_valid_to_date_s.day,
card_valid_to_date_s.month,
card_valid_to_date_s.year);
Expand All @@ -924,7 +924,7 @@ bool mosgortrans_parse_transport_block(const MfClassicBlock* block, FuriString*
1992);
furi_string_cat_printf(
result,
"Valid to: %02d.%02d.%04d\n",
"\nValid to: %02d.%02d.%04d",
card_valid_to_date_s.day,
card_valid_to_date_s.month,
card_valid_to_date_s.year);
Expand All @@ -939,7 +939,7 @@ bool mosgortrans_parse_transport_block(const MfClassicBlock* block, FuriString*
1992); //-time
furi_string_cat_printf(
result,
"Trip from: %02d.%02d.%04d %02d:%02d\n",
"\nTrip from: %02d.%02d.%04d %02d:%02d",
card_start_trip_minutes_s.day,
card_start_trip_minutes_s.month,
card_start_trip_minutes_s.year,
Expand All @@ -956,7 +956,7 @@ bool mosgortrans_parse_transport_block(const MfClassicBlock* block, FuriString*
1992);
furi_string_cat_printf(
result,
"Trip switch: %02d.%02d.%04d %02d:%02d\n",
"\nTrip switch: %02d.%02d.%04d %02d:%02d",
card_start_switch_trip_minutes_s.day,
card_start_switch_trip_minutes_s.month,
card_start_switch_trip_minutes_s.year,
Expand All @@ -965,7 +965,7 @@ bool mosgortrans_parse_transport_block(const MfClassicBlock* block, FuriString*
}
//transport
FuriString* transport = furi_string_alloc();
switch(data_block.transport_type) {
switch(data_block.transport_type) { // TODO: (-nofl) unused
case 1:
furi_string_cat(transport, "Metro");
break;
Expand All @@ -981,7 +981,7 @@ bool mosgortrans_parse_transport_block(const MfClassicBlock* block, FuriString*
}
//validator
if(data_block.validator) {
furi_string_cat_printf(result, "Validator: %05d", data_block.validator);
furi_string_cat_printf(result, "\nValidator: %05d", data_block.validator);
}
furi_string_free(transport);
break;
Expand Down Expand Up @@ -1094,14 +1094,14 @@ bool mosgortrans_parse_transport_block(const MfClassicBlock* block, FuriString*
data_block.valid_from_date * 24 * 60 + data_block.valid_for_minutes -
data_block.start_trip_neg_minutes,
&card_start_trip_minutes_s,
2016);
2016); // TODO: (-nofl) unused
//transport
FuriString* transport = furi_string_alloc();
parse_transport_type(&data_block, transport);
furi_string_cat_printf(result, "Transport: %s\n", furi_string_get_cstr(transport));
furi_string_cat_printf(result, "Transport: %s", furi_string_get_cstr(transport));
// validator
if(data_block.validator) {
furi_string_cat_printf(result, "Validator: %05d", data_block.validator);
furi_string_cat_printf(result, "\nValidator: %05d", data_block.validator);
}
furi_string_free(transport);
break;
Expand All @@ -1121,15 +1121,15 @@ bool mosgortrans_parse_transport_block(const MfClassicBlock* block, FuriString*
card_use_before_date_s.month,
card_use_before_date_s.year);
//remaining_funds
furi_string_cat_printf(result, "Balance: %ld rub\n", data_block.remaining_funds / 100);
furi_string_cat_printf(result, "Balance: %ld rub", data_block.remaining_funds / 100);
//start_trip_minutes
if(data_block.start_trip_minutes) {
DateTime card_start_trip_minutes_s = {0};
from_minutes_to_datetime(
data_block.start_trip_minutes, &card_start_trip_minutes_s, 2019);
furi_string_cat_printf(
result,
"Trip from: %02d.%02d.%04d %02d:%02d\n",
"\nTrip from: %02d.%02d.%04d %02d:%02d",
card_start_trip_minutes_s.day,
card_start_trip_minutes_s.month,
card_start_trip_minutes_s.year,
Expand All @@ -1145,7 +1145,7 @@ bool mosgortrans_parse_transport_block(const MfClassicBlock* block, FuriString*
2019);
furi_string_cat_printf(
result,
"(M) from: %02d.%02d.%04d %02d:%02d\n",
"\n(M) from: %02d.%02d.%04d %02d:%02d",
card_start_m_trip_minutes_s.day,
card_start_m_trip_minutes_s.month,
card_start_m_trip_minutes_s.year,
Expand All @@ -1160,7 +1160,7 @@ bool mosgortrans_parse_transport_block(const MfClassicBlock* block, FuriString*
2019);
furi_string_cat_printf(
result,
"Trip edit: %02d.%02d.%04d %02d:%02d\n",
"\nTrip edit: %02d.%02d.%04d %02d:%02d",
card_start_change_trip_minutes_s.day,
card_start_change_trip_minutes_s.month,
card_start_change_trip_minutes_s.year,
Expand All @@ -1170,7 +1170,7 @@ bool mosgortrans_parse_transport_block(const MfClassicBlock* block, FuriString*
//transport
//validator
if(data_block.validator) {
furi_string_cat_printf(result, "Validator: %05d", data_block.validator);
furi_string_cat_printf(result, "\nValidator: %05d", data_block.validator);
}
break;
}
Expand Down Expand Up @@ -1207,7 +1207,7 @@ bool mosgortrans_parse_transport_block(const MfClassicBlock* block, FuriString*
2019);
furi_string_cat_printf(
result,
"Valid to: %02d.%02d.%04d\n",
"Valid to: %02d.%02d.%04d",
card_use_to_date_s.day,
card_use_to_date_s.month,
card_use_to_date_s.year);
Expand All @@ -1221,7 +1221,7 @@ bool mosgortrans_parse_transport_block(const MfClassicBlock* block, FuriString*
2019); //-time
furi_string_cat_printf(
result,
"Trip from: %02d.%02d.%04d %02d:%02d\n",
"\nTrip from: %02d.%02d.%04d %02d:%02d",
card_start_trip_minutes_s.day,
card_start_trip_minutes_s.month,
card_start_trip_minutes_s.year,
Expand All @@ -1238,7 +1238,7 @@ bool mosgortrans_parse_transport_block(const MfClassicBlock* block, FuriString*
2019);
furi_string_cat_printf(
result,
"(M) from: %02d.%02d.%04d %02d:%02d\n",
"\n(M) from: %02d.%02d.%04d %02d:%02d",
card_start_trip_m_minutes_s.day,
card_start_trip_m_minutes_s.month,
card_start_trip_m_minutes_s.year,
Expand All @@ -1248,7 +1248,7 @@ bool mosgortrans_parse_transport_block(const MfClassicBlock* block, FuriString*
//transport
//validator
if(data_block.validator) {
furi_string_cat_printf(result, "Validator: %05d", data_block.validator);
furi_string_cat_printf(result, "\nValidator: %05d", data_block.validator);
}
break;
}
Expand Down
38 changes: 38 additions & 0 deletions applications/main/nfc/plugins/supported_cards/plantain.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,29 @@ static const MfClassicKeyPair plantain_4k_keys[] = {
{.a = 0xb27addfb64b0, .b = 0x152fd0c420a7}, {.a = 0x7259fa0197c6, .b = 0x5583698df085},
};

static const MfClassicKeyPair plantain_4k_keys_legacy[] = {
{.a = 0xffffffffffff, .b = 0xffffffffffff}, {.a = 0xffffffffffff, .b = 0xffffffffffff},
{.a = 0xffffffffffff, .b = 0xffffffffffff}, {.a = 0xffffffffffff, .b = 0xffffffffffff},
{.a = 0xe56ac127dd45, .b = 0x19fc84a3784b}, {.a = 0x77dabc9825e1, .b = 0x9764fec3154a},
{.a = 0xffffffffffff, .b = 0xffffffffffff}, {.a = 0xffffffffffff, .b = 0xffffffffffff},
{.a = 0x26973ea74321, .b = 0xd27058c6e2c7}, {.a = 0xeb0a8ff88ade, .b = 0x578a9ada41e3},
{.a = 0xea0fd73cb149, .b = 0x29c35fa068fb}, {.a = 0xc76bf71a2509, .b = 0x9ba241db3f56},
{.a = 0xacffffffffff, .b = 0x71f3a315ad26}, {.a = 0xffffffffffff, .b = 0xffffffffffff},
{.a = 0xffffffffffff, .b = 0xffffffffffff}, {.a = 0xffffffffffff, .b = 0xffffffffffff},
{.a = 0x72f96bdd3714, .b = 0x462225cd34cf}, {.a = 0x044ce1872bc3, .b = 0x8c90c70cff4a},
{.a = 0xbc2d1791dec1, .b = 0xca96a487de0b}, {.a = 0x8791b2ccb5c4, .b = 0xc956c3b80da3},
{.a = 0x8e26e45e7d65, .b = 0x8e65b3af7d22}, {.a = 0x0f318130ed18, .b = 0x0c420a20e056},
{.a = 0x045ceca15535, .b = 0x31bec3d9e510}, {.a = 0x9d993c5d4ef4, .b = 0x86120e488abf},
{.a = 0xc65d4eaa645b, .b = 0xb69d40d1a439}, {.a = 0x46d78e850a7e, .b = 0xa470f8130991},
{.a = 0x42e9b54e51ab, .b = 0x0231b86df52e}, {.a = 0x0f01ceff2742, .b = 0x6fec74559ca7},
{.a = 0xb81f2b0c2f66, .b = 0xa7e2d95f0003}, {.a = 0x9ea3387a63c1, .b = 0x437e59f57561},
{.a = 0x0eb23cc8110b, .b = 0x04dc35277635}, {.a = 0xbc4580b7f20b, .b = 0xd0a4131fb290},
{.a = 0x7a396f0d633d, .b = 0xad2bdc097023}, {.a = 0xa3faa6daff67, .b = 0x7600e889adf9},
{.a = 0xfd8705e721b0, .b = 0x296fc317a513}, {.a = 0x22052b480d11, .b = 0xe19504c39461},
{.a = 0xa7141147d430, .b = 0xff16014fefc7}, {.a = 0x8a8d88151a00, .b = 0x038b5f9b5a2a},
{.a = 0xb27addfb64b0, .b = 0x152fd0c420a7}, {.a = 0x7259fa0197c6, .b = 0x5583698df085},
};

static bool plantain_get_card_config(PlantainCardConfig* config, MfClassicType type) {
bool success = true;

Expand Down Expand Up @@ -126,6 +149,21 @@ static bool plantain_read(Nfc* nfc, NfcDevice* device) {
PlantainCardConfig cfg = {};
if(!plantain_get_card_config(&cfg, data->type)) break;

const uint8_t legacy_check_sec_num = 26;
const uint8_t legacy_check_block_num =
mf_classic_get_first_block_num_of_sector(legacy_check_sec_num);

MfClassicKey key = {0};
bit_lib_num_to_bytes_be(
plantain_4k_keys_legacy[legacy_check_sec_num].a, COUNT_OF(key.data), key.data);

error = mf_classic_poller_sync_auth(
nfc, legacy_check_block_num, &key, MfClassicKeyTypeA, NULL);
if(error == MfClassicErrorNone) {
FURI_LOG_D(TAG, "Legacy keys detected");
cfg.keys = plantain_4k_keys_legacy;
}

MfClassicDeviceKeys keys = {};
for(size_t i = 0; i < mf_classic_get_total_sectors_num(data->type); i++) {
bit_lib_num_to_bytes_be(cfg.keys[i].a, sizeof(MfClassicKey), keys.key_a[i].data);
Expand Down
4 changes: 2 additions & 2 deletions applications/main/nfc/plugins/supported_cards/troika.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,11 @@ static bool troika_parse(const NfcDevice* device, FuriString* parsed_data) {

if(result2) {
furi_string_cat_printf(
parsed_data, "\e#Ediniy\n%s\n", furi_string_get_cstr(ground_result));
parsed_data, "\n\e#Ediniy\n%s\n", furi_string_get_cstr(ground_result));
}

if(result3) {
furi_string_cat_printf(parsed_data, "\e#TAT\n%s\n", furi_string_get_cstr(tat_result));
furi_string_cat_printf(parsed_data, "\n\e#TAT\n%s", furi_string_get_cstr(tat_result));
}

furi_string_free(tat_result);
Expand Down
Loading

0 comments on commit c8ad76a

Please sign in to comment.