NFC: Improvements to NFC Magic app (#2760)
Ability to write gen1b tags (ignore 0x43) Ability to write gen1 7 byte UID tags Fix detection of non magic cards Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
		
							parent
							
								
									dcf105994b
								
							
						
					
					
						commit
						feebf2cd77
					
				| @ -46,6 +46,7 @@ enum NfcMagicCustomEvent { | |||||||
| struct NfcMagicDevice { | struct NfcMagicDevice { | ||||||
|     MagicType type; |     MagicType type; | ||||||
|     uint32_t cuid; |     uint32_t cuid; | ||||||
|  |     uint8_t uid_len; | ||||||
|     uint32_t password; |     uint32_t password; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -107,14 +107,7 @@ void nfc_magic_worker_write(NfcMagicWorker* nfc_magic_worker) { | |||||||
|                 } |                 } | ||||||
|                 magic_activate(); |                 magic_activate(); | ||||||
|                 if(magic_gen1_wupa()) { |                 if(magic_gen1_wupa()) { | ||||||
|                     if(!magic_gen1_data_access_cmd()) { |                     magic_gen1_data_access_cmd(); | ||||||
|                         FURI_LOG_E( |  | ||||||
|                             TAG, "No card response to data access command (not a magic card)"); |  | ||||||
|                         nfc_magic_worker->callback( |  | ||||||
|                             NfcMagicWorkerEventWrongCard, nfc_magic_worker->context); |  | ||||||
|                         done = true; |  | ||||||
|                         break; |  | ||||||
|                     } |  | ||||||
| 
 | 
 | ||||||
|                     MfClassicData* mfc_data = &dev_data->mf_classic_data; |                     MfClassicData* mfc_data = &dev_data->mf_classic_data; | ||||||
|                     for(size_t i = 0; i < 64; i++) { |                     for(size_t i = 0; i < 64; i++) { | ||||||
| @ -296,6 +289,7 @@ void nfc_magic_worker_write(NfcMagicWorker* nfc_magic_worker) { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void nfc_magic_worker_check(NfcMagicWorker* nfc_magic_worker) { | void nfc_magic_worker_check(NfcMagicWorker* nfc_magic_worker) { | ||||||
|  |     FuriHalNfcDevData nfc_data = {}; | ||||||
|     NfcMagicDevice* magic_dev = nfc_magic_worker->magic_dev; |     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]; |     uint8_t gen4_config[MAGIC_GEN4_CONFIG_LEN]; | ||||||
| @ -310,16 +304,21 @@ void nfc_magic_worker_check(NfcMagicWorker* nfc_magic_worker) { | |||||||
|                 card_found_notified = true; |                 card_found_notified = true; | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             furi_hal_nfc_activate_nfca(200, &magic_dev->cuid); |             if(furi_hal_nfc_detect(&nfc_data, 200)) { | ||||||
|  |                 magic_dev->cuid = nfc_data.cuid; | ||||||
|  |                 magic_dev->uid_len = nfc_data.uid_len; | ||||||
|  |             } else { | ||||||
|  |                 // wrong BCC
 | ||||||
|  |                 magic_dev->uid_len = 4; | ||||||
|  |             } | ||||||
|             nfc_magic_worker->callback(NfcMagicWorkerEventSuccess, nfc_magic_worker->context); |             nfc_magic_worker->callback(NfcMagicWorkerEventSuccess, nfc_magic_worker->context); | ||||||
|             break; |             break; | ||||||
|         } |         } else { | ||||||
| 
 |  | ||||||
|             magic_deactivate(); |             magic_deactivate(); | ||||||
|         furi_delay_ms(300); |  | ||||||
|             magic_activate(); |             magic_activate(); | ||||||
| 
 |             if(furi_hal_nfc_detect(&nfc_data, 200)) { | ||||||
|         furi_hal_nfc_activate_nfca(200, &magic_dev->cuid); |                 magic_dev->cuid = nfc_data.cuid; | ||||||
|  |                 magic_dev->uid_len = nfc_data.uid_len; | ||||||
|                 if(magic_gen4_get_cfg(magic_dev->password, gen4_config)) { |                 if(magic_gen4_get_cfg(magic_dev->password, gen4_config)) { | ||||||
|                     magic_dev->type = MagicTypeGen4; |                     magic_dev->type = MagicTypeGen4; | ||||||
|                     if(!card_found_notified) { |                     if(!card_found_notified) { | ||||||
| @ -328,15 +327,22 @@ void nfc_magic_worker_check(NfcMagicWorker* nfc_magic_worker) { | |||||||
|                         card_found_notified = true; |                         card_found_notified = true; | ||||||
|                     } |                     } | ||||||
| 
 | 
 | ||||||
|             nfc_magic_worker->callback(NfcMagicWorkerEventSuccess, nfc_magic_worker->context); |                     nfc_magic_worker->callback( | ||||||
|             break; |                         NfcMagicWorkerEventSuccess, nfc_magic_worker->context); | ||||||
|  |                 } else { | ||||||
|  |                     nfc_magic_worker->callback( | ||||||
|  |                         NfcMagicWorkerEventWrongCard, nfc_magic_worker->context); | ||||||
|  |                     card_found_notified = true; | ||||||
|                 } |                 } | ||||||
| 
 |                 break; | ||||||
|  |             } else { | ||||||
|                 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; | ||||||
|                 } |                 } | ||||||
|  |             } | ||||||
|  |         } | ||||||
| 
 | 
 | ||||||
|         magic_deactivate(); |         magic_deactivate(); | ||||||
|         furi_delay_ms(300); |         furi_delay_ms(300); | ||||||
|  | |||||||
| @ -8,7 +8,7 @@ static bool nfc_magic_scene_file_select_is_file_suitable(NfcMagic* nfc_magic) { | |||||||
|         case MagicTypeClassicDirectWrite: |         case MagicTypeClassicDirectWrite: | ||||||
|         case MagicTypeClassicAPDU: |         case MagicTypeClassicAPDU: | ||||||
|             if((nfc_dev->dev_data.mf_classic_data.type != MfClassicType1k) || |             if((nfc_dev->dev_data.mf_classic_data.type != MfClassicType1k) || | ||||||
|                (nfc_dev->dev_data.nfc_data.uid_len != 4)) { |                (nfc_dev->dev_data.nfc_data.uid_len != nfc_magic->dev->uid_len)) { | ||||||
|                 return false; |                 return false; | ||||||
|             } |             } | ||||||
|             return true; |             return true; | ||||||
|  | |||||||
| @ -13,11 +13,10 @@ void nfc_magic_scene_not_magic_on_enter(void* context) { | |||||||
| 
 | 
 | ||||||
|     notification_message(nfc_magic->notifications, &sequence_error); |     notification_message(nfc_magic->notifications, &sequence_error); | ||||||
| 
 | 
 | ||||||
|     // widget_add_icon_element(widget, 73, 17, &I_DolphinCommon_56x48);
 |  | ||||||
|     widget_add_string_element( |     widget_add_string_element( | ||||||
|         widget, 3, 4, AlignLeft, AlignTop, FontPrimary, "This is wrong card"); |         widget, 3, 4, AlignLeft, AlignTop, FontPrimary, "This is wrong card"); | ||||||
|     widget_add_string_multiline_element( |     widget_add_string_multiline_element( | ||||||
|         widget, 4, 17, AlignLeft, AlignTop, FontSecondary, "Not a magic\ncard"); |         widget, 4, 17, AlignLeft, AlignTop, FontSecondary, "Not magic or unsupported\ncard"); | ||||||
|     widget_add_button_element( |     widget_add_button_element( | ||||||
|         widget, GuiButtonTypeLeft, "Retry", nfc_magic_scene_not_magic_widget_callback, nfc_magic); |         widget, GuiButtonTypeLeft, "Retry", nfc_magic_scene_not_magic_widget_callback, nfc_magic); | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 AloneLiberty
						AloneLiberty