@@ -4541,7 +4541,7 @@ static int CmdHF14ADesValueOperations(const char *Cmd) {
4541
4541
arg_str0 (NULL , "aid" , "<hex>" , "Application ID (3 hex bytes, big endian)" ),
4542
4542
arg_str0 (NULL , "isoid" , "<hex>" , "Application ISO ID (ISO DF ID) (2 hex bytes, big endian)" ),
4543
4543
arg_str0 (NULL , "fid" , "<hex>" , "File ID (1 hex byte)" ),
4544
- arg_str0 ("o" , "op" , "<get/credit/limcredit/debit/clear>" , "Operation: get(default)/credit/limcredit(limited credit)/debit/clear. Operation clear: get-getopt-debit to min value" ),
4544
+ arg_str0 ("o" , "op" , "<get/credit/limcredit/debit/clear>" , "Operation: get(default)/credit/limcredit(limited credit)/debit/clear. Additional operation clear: get-getopt-debit to min value" ),
4545
4545
arg_str0 ("d" , "data" , "<hex>" , "Value for operation (HEX 4 bytes)" ),
4546
4546
arg_lit0 (NULL , "no-auth" , "Execute without authentication" ),
4547
4547
arg_param_end
@@ -4623,18 +4623,21 @@ static int CmdHF14ADesValueOperations(const char *Cmd) {
4623
4623
PrintAndLogEx (SUCCESS , "Value changed " _GREEN_ ("successfully" ));
4624
4624
}
4625
4625
} else {
4626
+ DesfireCommunicationMode fileCommMode = dctx .commMode ;
4627
+
4626
4628
res = DesfireValueFileOperations (& dctx , fileid , MFDES_GET_VALUE , & value );
4627
4629
if (res != PM3_SUCCESS ) {
4628
4630
PrintAndLogEx (ERR , "Desfire GetValue command ( " _RED_ ("error" ) ") Result: %d" , res );
4629
4631
DropField ();
4630
4632
return PM3_ESOFT ;
4631
4633
}
4632
4634
if (verbose )
4633
- PrintAndLogEx (INFO , "current value: 0x%08x" , value );
4635
+ PrintAndLogEx (INFO , _YELLOW_ ( "GetValue" ) " command is " _GREEN_ ( "ok" ) ". Current value: 0x%08x" , value );
4634
4636
4635
4637
uint8_t buf [250 ] = {0 };
4636
4638
size_t buflen = 0 ;
4637
4639
4640
+ DesfireSetCommMode (& dctx , DCMMACed );
4638
4641
res = DesfireGetFileSettings (& dctx , fileid , buf , & buflen );
4639
4642
if (res != PM3_SUCCESS ) {
4640
4643
PrintAndLogEx (ERR , "Desfire GetFileSettings command ( " _RED_ ("error" ) " ) Result: %d" , res );
@@ -4643,22 +4646,41 @@ static int CmdHF14ADesValueOperations(const char *Cmd) {
4643
4646
}
4644
4647
4645
4648
if (verbose )
4646
- PrintAndLogEx (INFO , "file settings[%zu]: %s" , buflen , sprint_hex (buf , buflen ));
4649
+ PrintAndLogEx (INFO , _YELLOW_ ( "GetFileSettings" ) " is " _GREEN_(" ok ") " . File settings [%zu ]: %s ", buflen, sprint_hex(buf, buflen));
4647
4650
4648
4651
if (buflen < 8 || buf [0 ] != 0x02 ) {
4649
4652
PrintAndLogEx (ERR , "Desfire GetFileSettings command returns " _RED_ ("wrong" ) " data" );
4650
4653
DropField ();
4651
4654
return PM3_ESOFT ;
4652
4655
}
4653
4656
4654
- uint32_t minvalue = MemLeToUint4byte (& buf [4 ]);
4655
- uint32_t delta = (value > minvalue ) ? value - minvalue : 0 ;
4657
+ int32_t minvalue = ( int ) MemLeToUint4byte (& buf [4 ]);
4658
+ uint32_t delta = (( int64_t ) value > minvalue ) ? value - minvalue : 0 ;
4656
4659
if (verbose ) {
4657
- PrintAndLogEx (INFO , "minimum value: 0x%08x" , minvalue );
4658
- PrintAndLogEx (INFO , "delta value : 0x%08x" , delta );
4660
+ PrintAndLogEx (INFO , "value: 0x%08x (%d)" , value , value );
4661
+ PrintAndLogEx (INFO , "minimum value: 0x%08x (%d)" , minvalue , minvalue );
4662
+ PrintAndLogEx (INFO , "delta value : 0x%08x (%d)" , delta , delta );
4659
4663
}
4660
4664
4661
4665
if (delta > 0 ) {
4666
+ DesfireSetCommMode (& dctx , fileCommMode );
4667
+
4668
+ uint32_t maxdelta = 0x7fffffff ;
4669
+ if (delta > maxdelta ) {
4670
+ res = DesfireValueFileOperations (& dctx , fileid , MFDES_DEBIT , & maxdelta );
4671
+ if (res != PM3_SUCCESS ) {
4672
+ PrintAndLogEx (ERR , "Desfire Debit maxdelta operation ( " _RED_ ("error" ) " ) Result: %d" , res );
4673
+ DropField ();
4674
+ return PM3_ESOFT ;
4675
+ }
4676
+
4677
+ delta -= maxdelta ;
4678
+ if (verbose ) {
4679
+ PrintAndLogEx (INFO , "Value maxdelta debited " _GREEN_ ("ok" ));
4680
+ PrintAndLogEx (INFO , "delta value : 0x%08x (%d)" , delta , delta );
4681
+ }
4682
+ }
4683
+
4662
4684
res = DesfireValueFileOperations (& dctx , fileid , MFDES_DEBIT , & delta );
4663
4685
if (res != PM3_SUCCESS ) {
4664
4686
PrintAndLogEx (ERR , "Desfire Debit operation ( " _RED_ ("error" ) " ) Result: %d" , res );
@@ -4667,7 +4689,7 @@ static int CmdHF14ADesValueOperations(const char *Cmd) {
4667
4689
}
4668
4690
4669
4691
if (verbose )
4670
- PrintAndLogEx (INFO , "Value debited" );
4692
+ PrintAndLogEx (INFO , "Value debited " _GREEN_ ( "ok" ) );
4671
4693
4672
4694
DesfireSetCommMode (& dctx , DCMMACed );
4673
4695
res = DesfireCommitTransaction (& dctx , false, 0 );
@@ -4678,7 +4700,7 @@ static int CmdHF14ADesValueOperations(const char *Cmd) {
4678
4700
}
4679
4701
4680
4702
if (verbose )
4681
- PrintAndLogEx (INFO , "Transaction committed" );
4703
+ PrintAndLogEx (INFO , "Transaction :" _GREEN_ ( " committed") );
4682
4704
} else {
4683
4705
if (verbose )
4684
4706
PrintAndLogEx (INFO , "Nothing to clear. Value already in the minimum level." );
0 commit comments