2010-02-21 05:24:25 +08:00
//-----------------------------------------------------------------------------
// Jonathan Westhues, Aug 2005
2011-05-18 20:33:32 +08:00
// Gerhard de Koning Gans, April 2008, May 2011
2010-02-21 08:12:52 +08:00
//
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
// at your option, any later version. See the LICENSE.txt file for the text of
// the license.
//-----------------------------------------------------------------------------
// Definitions internal to the app source.
2010-02-21 05:24:25 +08:00
//-----------------------------------------------------------------------------
# ifndef __APPS_H
# define __APPS_H
2017-01-25 07:33:03 +08:00
# ifdef __cplusplus
extern " C " {
# endif
2014-09-12 05:23:46 +08:00
# include <stdlib.h>
2017-01-25 07:33:03 +08:00
# include <stdarg.h>
2015-07-23 05:00:52 +08:00
# include "common.h"
2017-01-25 07:33:03 +08:00
# include "usb_cdc.h"
2015-07-23 05:00:52 +08:00
# include "crc32.h"
# include "lfdemod.h"
2015-01-16 18:00:17 +08:00
# include "BigBuf.h"
2015-06-25 18:22:34 +08:00
# include "fpgaloader.h"
2015-07-19 02:43:14 +08:00
# include "hitag2.h"
2016-03-05 02:06:47 +08:00
# include "hitagS.h"
2015-07-19 02:43:14 +08:00
# include "mifare.h"
2015-10-14 17:39:51 +08:00
# include "pcf7931.h"
2015-03-24 18:45:31 +08:00
# include "desfire.h"
2016-03-21 02:33:07 +08:00
# include "iso14443b.h"
2017-08-26 18:57:18 +08:00
# include "Standalone/standalone.h"
2018-02-13 22:45:15 +08:00
# include "flashmem.h"
2014-12-18 03:33:21 +08:00
2017-07-30 15:17:48 +08:00
extern const uint8_t OddByteParity [ 256 ] ;
2012-06-28 21:38:40 +08:00
extern int rsamples ; // = 0;
extern uint8_t trigger ;
2010-02-21 05:24:25 +08:00
2010-10-08 18:23:04 +08:00
// This may be used (sparingly) to declare a function to be copied to
// and executed from RAM
# define RAMFUNC __attribute((long_call, section(".ramfunc")))
2010-02-21 05:24:25 +08:00
/// appmain.h
void ReadMem ( int addr ) ;
void __attribute__ ( ( noreturn ) ) AppMain ( void ) ;
//void DbpIntegers(int a, int b, int c);
void DbpString ( char * str ) ;
2019-06-08 03:26:03 +08:00
void DbpStringEx ( uint32_t flags , char * str ) ;
2010-02-21 05:24:25 +08:00
void Dbprintf ( const char * fmt , . . . ) ;
2019-06-08 03:26:03 +08:00
void DbprintfEx ( uint32_t flags , const char * fmt , . . . ) ;
2012-09-18 21:53:17 +08:00
void Dbhexdump ( int len , uint8_t * d , bool bAsci ) ;
2010-02-21 05:24:25 +08:00
2015-02-03 14:21:57 +08:00
// ADC Vref = 3300mV, and an (10M+1M):1M voltage divider on the HF input can measure voltages up to 36300 mV
# define MAX_ADC_HF_VOLTAGE 36300
2018-02-07 20:11:10 +08:00
// ADC Vref = 3300mV, (240k-10M):240k voltage divider, 140800 mV
# define MAX_ADC_HF_VOLTAGE_RDV40 140800
2015-02-03 14:21:57 +08:00
// ADC Vref = 3300mV, and an (10000k+240k):240k voltage divider on the LF input can measure voltages up to 140800 mV
# define MAX_ADC_LF_VOLTAGE 140800
2018-02-13 18:40:05 +08:00
uint16_t AvgAdc ( int ch ) ;
2011-06-10 21:35:10 +08:00
2017-01-25 07:33:03 +08:00
void print_result ( char * name , uint8_t * buf , size_t len ) ;
2019-04-07 17:36:24 +08:00
//void PrintToSendBuffer(void);
2010-02-21 05:24:25 +08:00
void ToSendStuffBit ( int b ) ;
void ToSendReset ( void ) ;
2019-05-20 16:28:34 +08:00
void ListenReaderField ( uint8_t limit ) ;
2010-02-21 05:24:25 +08:00
extern int ToSendMax ;
2010-02-21 06:51:00 +08:00
extern uint8_t ToSend [ ] ;
2010-02-21 05:24:25 +08:00
2019-04-06 07:00:54 +08:00
void StandAloneMode ( void ) ;
void printStandAloneModes ( void ) ;
2017-08-26 18:57:18 +08:00
2010-02-21 05:24:25 +08:00
/// lfops.h
2015-01-29 07:57:22 +08:00
extern uint8_t decimation ;
extern uint8_t bits_per_sample ;
extern bool averaging ;
2013-09-27 21:48:20 +08:00
void AcquireRawAdcSamples125k ( int divisor ) ;
2015-10-21 01:00:02 +08:00
void ModThenAcquireRawAdcSamples125k ( uint32_t delay_off , uint32_t period_0 , uint32_t period_1 , uint8_t * command ) ;
2010-02-21 05:24:25 +08:00
void ReadTItag ( void ) ;
2010-02-21 06:51:00 +08:00
void WriteTItag ( uint32_t idhi , uint32_t idlo , uint16_t crc ) ;
2015-10-21 01:00:02 +08:00
2010-02-21 05:24:25 +08:00
void AcquireTiType ( void ) ;
void AcquireRawBitsTI ( void ) ;
2019-05-24 21:11:30 +08:00
void SimulateTagLowFrequencyEx ( int period , int gap , bool ledcontrol , int numcycles ) ;
void SimulateTagLowFrequency ( int period , int gap , bool ledcontrol ) ;
2015-11-23 00:33:41 +08:00
void SimulateTagLowFrequencyBidir ( int divisor , int max_bitlen ) ;
2019-05-24 01:16:06 +08:00
2019-05-24 21:11:30 +08:00
void CmdHIDsimTAGEx ( uint32_t hi , uint32_t lo , bool ledcontrol , int numcycles ) ;
void CmdHIDsimTAG ( uint32_t hi , uint32_t lo , bool ledcontrol ) ;
2019-05-24 01:16:06 +08:00
2019-05-24 21:11:30 +08:00
void CmdFSKsimTAG ( uint8_t fchigh , uint8_t fclow , uint8_t separator , uint8_t clk , uint16_t bitslen , uint8_t * bits , bool ledcontrol ) ;
void CmdASKsimTAG ( uint8_t encoding , uint8_t invert , uint8_t separator , uint8_t clk , uint16_t size , uint8_t * bits , bool ledcontrol ) ;
void CmdPSKsimTag ( uint8_t carrier , uint8_t invert , uint8_t clk , uint16_t size , uint8_t * bits , bool ledcontrol ) ;
2019-05-24 19:06:08 +08:00
2017-10-29 10:26:46 +08:00
void CmdHIDdemodFSK ( int findone , uint32_t * high , uint32_t * low , int ledcontrol ) ;
void CmdAWIDdemodFSK ( int findone , uint32_t * high , uint32_t * low , int ledcontrol ) ; // Realtime demodulation mode for AWID26
2017-10-29 18:20:10 +08:00
void CmdEM410xdemod ( int findone , uint32_t * high , uint64_t * low , int ledcontrol ) ;
2017-10-29 10:26:46 +08:00
void CmdIOdemodFSK ( int findone , uint32_t * high , uint32_t * low , int ledcontrol ) ;
2015-11-03 03:46:17 +08:00
void CopyIOtoT55x7 ( uint32_t hi , uint32_t lo ) ; // Clone an ioProx card to T5557/T5567
2013-03-01 01:04:23 +08:00
void CopyHIDtoT55x7 ( uint32_t hi2 , uint32_t hi , uint32_t lo , uint8_t longFMT ) ; // Clone an HID card to T5557/T5567
2015-11-23 00:33:41 +08:00
void CopyVikingtoT55xx ( uint32_t block1 , uint32_t block2 , uint8_t Q5 ) ;
2012-03-07 21:44:53 +08:00
void WriteEM410x ( uint32_t card , uint32_t id_hi , uint32_t id_lo ) ;
2015-10-28 04:47:21 +08:00
void CopyIndala64toT55x7 ( uint32_t hi , uint32_t lo ) ; // Clone Indala 64-bit tag by UID to T55x7
void CopyIndala224toT55x7 ( uint32_t uid1 , uint32_t uid2 , uint32_t uid3 , uint32_t uid4 , uint32_t uid5 , uint32_t uid6 , uint32_t uid7 ) ; // Clone Indala 224-bit tag by UID to T55x7
2015-11-03 03:46:17 +08:00
void T55xxResetRead ( void ) ;
2019-05-13 19:23:53 +08:00
void T55xxWriteBlock ( uint8_t * data ) ;
void T55xxWriteBlockExt ( uint32_t data , uint8_t blockno , uint32_t pwd , uint8_t flags ) ;
2019-05-22 23:59:39 +08:00
void T55xxReadBlock ( uint8_t page , bool pwd_mode , bool brute_mem , uint8_t block , uint32_t pwd ) ;
2015-10-21 01:00:02 +08:00
void T55xxWakeUp ( uint32_t Pwd ) ;
2019-01-11 21:46:27 +08:00
void T55xx_ChkPwds ( void ) ;
2016-10-09 01:12:51 +08:00
void TurnReadLFOn ( uint32_t delay ) ;
2019-05-28 17:15:12 +08:00
2017-02-08 05:26:06 +08:00
void EM4xReadWord ( uint8_t addr , uint32_t pwd , uint8_t usepwd ) ;
2019-05-28 17:15:12 +08:00
void EM4xWriteWord ( uint8_t addr , uint32_t data , uint32_t pwd , uint8_t usepwd ) ;
2017-02-02 22:32:21 +08:00
void Cotag ( uint32_t arg0 ) ;
2018-09-23 11:29:55 +08:00
void setT55xxConfig ( uint8_t arg0 , t55xx_config * c ) ;
2019-03-10 07:00:59 +08:00
t55xx_config * getT55xxConfig ( void ) ;
2018-09-12 00:35:07 +08:00
void printT55xxConfig ( void ) ;
void loadT55xxConfig ( void ) ;
2010-02-21 05:24:25 +08:00
2016-08-05 03:51:26 +08:00
/// iso14443b.h
2016-04-27 17:21:29 +08:00
void SimulateIso14443bTag ( uint32_t pupi ) ;
2015-06-18 15:52:53 +08:00
void AcquireRawAdcSamplesIso14443b ( uint32_t parameter ) ;
2016-03-21 02:33:07 +08:00
void ReadSTMemoryIso14443b ( uint8_t numofblocks ) ;
2018-01-07 04:12:28 +08:00
void RAMFUNC SniffIso14443b ( void ) ;
2013-09-02 02:41:05 +08:00
void SendRawCommand14443B ( uint32_t , uint32_t , uint8_t , uint8_t [ ] ) ;
2019-04-18 18:43:35 +08:00
void SendRawCommand14443B_Ex ( PacketCommandNG * c ) ;
2017-01-25 07:33:03 +08:00
void ClearFpgaShiftingRegisters ( void ) ;
2010-02-21 05:24:25 +08:00
2016-08-05 03:51:26 +08:00
// iso14443a.h
2015-05-16 21:34:01 +08:00
void RAMFUNC SniffIso14443a ( uint8_t param ) ;
2019-04-18 18:43:35 +08:00
void ReaderIso14443a ( PacketCommandNG * c ) ;
2018-02-28 20:21:47 +08:00
2012-06-28 21:38:40 +08:00
// Also used in iclass.c
2016-05-09 00:52:19 +08:00
//bool RAMFUNC LogTrace(const uint8_t *btBytes, uint16_t len, uint32_t timestamp_start, uint32_t timestamp_end, uint8_t *parity, bool readerToTag);
2019-04-07 02:21:03 +08:00
void GetParity ( const uint8_t * pbtCmd , uint16_t len , uint8_t * par ) ;
2012-12-05 07:39:18 +08:00
void iso14a_set_trigger ( bool enable ) ;
2017-03-02 04:51:23 +08:00
// also used in emv
2019-03-16 04:04:25 +08:00
//bool prepare_allocated_tag_modulation(tag_response_info_t *response_info);
//int GetIso14443aCommandFromReader(uint8_t *received, uint8_t *parity, int *len);
2015-02-08 03:49:40 +08:00
2016-08-05 03:51:26 +08:00
// epa.h
2019-04-18 18:43:35 +08:00
void EPA_PACE_Collect_Nonce ( PacketCommandNG * c ) ;
void EPA_PACE_Replay ( PacketCommandNG * c ) ;
2012-08-29 05:39:50 +08:00
2011-06-18 02:39:54 +08:00
// mifarecmd.h
2019-05-29 01:20:56 +08:00
void MifareReadBlock ( uint8_t blockNo , uint8_t keyType , uint8_t * datain ) ;
2015-03-24 18:45:31 +08:00
void MifareUReadBlock ( uint8_t arg0 , uint8_t arg1 , uint8_t * datain ) ;
2019-04-07 18:30:49 +08:00
void MifareUC_Auth ( uint8_t arg0 , uint8_t * keybytes ) ;
2015-05-05 06:34:20 +08:00
void MifareUReadCard ( uint8_t arg0 , uint16_t arg1 , uint8_t arg2 , uint8_t * datain ) ;
2019-05-13 18:49:41 +08:00
void MifareReadSector ( uint8_t arg0 , uint8_t arg1 , uint8_t * datain ) ;
void MifareWriteBlock ( uint8_t arg0 , uint8_t arg1 , uint8_t * datain ) ;
2015-05-28 05:23:46 +08:00
//void MifareUWriteBlockCompat(uint8_t arg0,uint8_t *datain);
void MifareUWriteBlock ( uint8_t arg0 , uint8_t arg1 , uint8_t * datain ) ;
2011-06-07 20:35:52 +08:00
void MifareNested ( uint32_t arg0 , uint32_t arg1 , uint32_t arg2 , uint8_t * datain ) ;
2015-11-27 23:24:00 +08:00
void MifareAcquireEncryptedNonces ( uint32_t arg0 , uint32_t arg1 , uint32_t flags , uint8_t * datain ) ;
2019-05-13 19:31:11 +08:00
void MifareAcquireNonces ( uint32_t arg0 , uint32_t flags ) ;
2019-05-13 18:25:11 +08:00
void MifareChkKeys ( uint8_t * datain ) ;
2017-10-05 22:00:56 +08:00
void MifareChkKeys_fast ( uint32_t arg0 , uint32_t arg1 , uint32_t arg2 , uint8_t * datain ) ;
2019-05-27 19:46:27 +08:00
2019-05-13 18:30:27 +08:00
void MifareEMemClr ( void ) ;
2019-05-27 19:46:27 +08:00
void MifareEMemSet ( uint8_t blockno , uint8_t blockcnt , uint8_t blockwidth , uint8_t * datain ) ;
void MifareEMemGet ( uint8_t blockno , uint8_t blockcnt ) ;
2019-05-23 15:03:24 +08:00
int MifareECardLoad ( uint32_t arg0 , uint32_t arg1 ) ;
2019-05-27 19:46:27 +08:00
2015-11-10 04:46:15 +08:00
void MifareCSetBlock ( uint32_t arg0 , uint32_t arg1 , uint8_t * datain ) ; // Work with "magic Chinese" card
void MifareCGetBlock ( uint32_t arg0 , uint32_t arg1 , uint8_t * datain ) ;
2014-12-27 04:32:58 +08:00
void MifareCIdent ( ) ; // is "magic chinese" card?
2019-05-27 19:46:27 +08:00
2019-05-15 18:52:22 +08:00
void MifareSetMod ( uint8_t * datain ) ;
2015-03-30 22:24:03 +08:00
void MifareUSetPwd ( uint8_t arg0 , uint8_t * datain ) ;
2015-11-10 04:46:15 +08:00
void OnSuccessMagic ( ) ;
void OnErrorMagic ( uint8_t reason ) ;
2015-04-25 00:41:49 +08:00
2016-08-05 03:51:26 +08:00
int32_t dist_nt ( uint32_t nt1 , uint32_t nt2 ) ;
2019-03-10 07:00:59 +08:00
void ReaderMifare ( bool first_try , uint8_t block , uint8_t keytype ) ;
2018-01-18 21:11:22 +08:00
//void RAMFUNC SniffMifare(uint8_t param);
2016-08-05 03:51:26 +08:00
2014-12-31 18:35:43 +08:00
//desfire
2019-03-10 07:00:59 +08:00
void Mifare_DES_Auth1 ( uint8_t arg0 , uint8_t * datain ) ;
2019-03-09 15:59:13 +08:00
void Mifare_DES_Auth2 ( uint32_t arg0 , uint8_t * datain ) ;
2014-12-31 18:35:43 +08:00
2014-09-12 05:23:46 +08:00
// mifaredesfire.h
2016-08-05 03:51:26 +08:00
bool InitDesfireCard ( ) ;
2019-03-10 07:00:59 +08:00
void MifareSendCommand ( uint8_t arg0 , uint8_t arg1 , uint8_t * datain ) ;
2016-08-05 03:51:26 +08:00
void MifareDesfireGetInformation ( ) ;
2019-03-10 07:00:59 +08:00
void MifareDES_Auth1 ( uint8_t arg0 , uint8_t arg1 , uint8_t arg2 , uint8_t * datain ) ;
void ReaderMifareDES ( uint32_t param , uint32_t param2 , uint8_t * datain ) ;
2016-08-05 03:51:26 +08:00
int DesfireAPDU ( uint8_t * cmd , size_t cmd_len , uint8_t * dataout ) ;
2019-03-10 07:00:59 +08:00
size_t CreateAPDU ( uint8_t * datain , size_t len , uint8_t * dataout ) ;
2016-08-05 03:51:26 +08:00
void OnSuccess ( ) ;
void OnError ( uint8_t reason ) ;
2014-10-07 01:42:50 +08:00
2015-03-24 18:45:31 +08:00
// desfire_crypto.h
2019-03-10 07:00:59 +08:00
void * mifare_cryto_preprocess_data ( desfiretag_t tag , void * data , size_t * nbytes , size_t offset , int communication_settings ) ;
void * mifare_cryto_postprocess_data ( desfiretag_t tag , void * data , size_t * nbytes , int communication_settings ) ;
void mifare_cypher_single_block ( desfirekey_t key , uint8_t * data , uint8_t * ivect , MifareCryptoDirection direction , MifareCryptoOperation operation , size_t block_size ) ;
void mifare_cypher_blocks_chained ( desfiretag_t tag , desfirekey_t key , uint8_t * ivect , uint8_t * data , size_t data_size , MifareCryptoDirection direction , MifareCryptoOperation operation ) ;
size_t key_block_size ( const desfirekey_t key ) ;
size_t padded_data_length ( const size_t nbytes , const size_t block_size ) ;
size_t maced_data_length ( const desfirekey_t key , const size_t nbytes ) ;
size_t enciphered_data_length ( const desfiretag_t tag , const size_t nbytes , int communication_settings ) ;
void cmac_generate_subkeys ( desfirekey_t key ) ;
void cmac ( const desfirekey_t key , uint8_t * ivect , const uint8_t * data , size_t len , uint8_t * cmac ) ;
2014-09-12 05:23:46 +08:00
2017-02-23 07:03:10 +08:00
// iso15693.h
2010-10-19 22:25:17 +08:00
void RecordRawAdcSamplesIso15693 ( void ) ;
2010-02-21 05:24:25 +08:00
void AcquireRawAdcSamplesIso15693 ( void ) ;
2019-03-10 03:34:41 +08:00
void ReaderIso15693 ( uint32_t parameter ) ; // Simulate an ISO15693 reader - greg
void SimTagIso15693 ( uint32_t parameter , uint8_t * uid ) ; // simulate an ISO15693 tag - greg
2010-10-19 22:25:17 +08:00
void BruteforceIso15693Afi ( uint32_t speed ) ; // find an AFI of a tag - atrox
2019-03-10 07:00:59 +08:00
void DirectTag15693Command ( uint32_t datalen , uint32_t speed , uint32_t recv , uint8_t * data ) ; // send arbitrary commands from CLI - atrox
2017-08-31 19:24:12 +08:00
void Iso15693InitReader ( void ) ;
2010-02-21 05:24:25 +08:00
2017-02-23 07:03:10 +08:00
// iclass.h
2017-08-26 18:57:18 +08:00
void RAMFUNC SniffIClass ( void ) ;
2014-04-17 15:53:54 +08:00
void SimulateIClass ( uint32_t arg0 , uint32_t arg1 , uint32_t arg2 , uint8_t * datain ) ;
2012-06-28 21:38:40 +08:00
void ReaderIClass ( uint8_t arg0 ) ;
2019-04-07 02:21:03 +08:00
void ReaderIClass_Replay ( uint8_t arg0 , uint8_t * mac ) ;
void iClass_Authentication ( uint8_t * mac ) ;
2017-12-21 17:13:40 +08:00
void iClass_Authentication_fast ( uint64_t arg0 , uint64_t arg1 , uint8_t * datain ) ;
2019-04-07 02:21:03 +08:00
void iClass_WriteBlock ( uint8_t blockno , uint8_t * data ) ;
void iClass_ReadBlk ( uint8_t blockno ) ;
bool iClass_ReadBlock ( uint8_t blockno , uint8_t * data , uint8_t len ) ;
2015-10-08 05:00:46 +08:00
void iClass_Dump ( uint8_t blockno , uint8_t numblks ) ;
void iClass_Clone ( uint8_t startblock , uint8_t endblock , uint8_t * data ) ;
2019-04-07 02:21:03 +08:00
void iClass_ReadCheck ( uint8_t blockno , uint8_t keytype ) ;
2011-05-18 20:33:32 +08:00
2012-12-06 00:14:10 +08:00
// cmd.h
2019-04-23 04:58:45 +08:00
int reply_old ( uint64_t cmd , uint64_t arg0 , uint64_t arg1 , uint64_t arg2 , void * data , size_t len ) ;
int reply_mix ( uint64_t cmd , uint64_t arg0 , uint64_t arg1 , uint64_t arg2 , void * data , size_t len ) ;
int reply_ng ( uint16_t cmd , int16_t status , uint8_t * data , size_t len ) ;
int receive_ng ( PacketCommandNG * rx ) ;
2012-12-06 00:14:10 +08:00
2016-08-05 03:51:26 +08:00
// util.h
2019-03-12 20:15:39 +08:00
void HfSniff ( int , int ) ;
2016-08-05 03:51:26 +08:00
2017-10-21 02:27:44 +08:00
//felica.c
2019-04-18 18:43:35 +08:00
void felica_sendraw ( PacketCommandNG * c ) ;
2019-04-06 07:00:54 +08:00
void felica_sniff ( uint32_t samplesToSkip , uint32_t triggersToSkip ) ;
void felica_sim_lite ( uint64_t uid ) ;
void felica_dump_lite_s ( ) ;
2017-10-21 02:27:44 +08:00
2018-02-13 22:45:15 +08:00
2017-01-25 07:33:03 +08:00
# ifdef __cplusplus
}
# endif
2010-02-21 05:24:25 +08:00
# endif