2010-02-20 21:24:25 +00:00
//-----------------------------------------------------------------------------
// Jonathan Westhues, Aug 2005
2011-05-18 12:33:32 +00:00
// Gerhard de Koning Gans, April 2008, May 2011
2010-02-21 00:12:52 +00: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-20 21:24:25 +00:00
//-----------------------------------------------------------------------------
# ifndef __APPS_H
# define __APPS_H
2017-01-25 00:33:03 +01:00
# ifdef __cplusplus
extern " C " {
# endif
2014-09-11 23:23:46 +02:00
# include <stdlib.h>
2017-01-25 00:33:03 +01:00
# include <stdarg.h>
2015-07-22 23:00:52 +02:00
# include "common.h"
2017-01-25 00:33:03 +01:00
# include "usb_cdc.h"
2015-07-22 23:00:52 +02:00
# include "crc32.h"
# include "lfdemod.h"
2015-01-16 11:00:17 +01:00
# include "BigBuf.h"
2015-06-25 12:22:34 +02:00
# include "fpgaloader.h"
2015-07-18 20:43:14 +02:00
# include "hitag2.h"
2016-03-04 19:06:47 +01:00
# include "hitagS.h"
2015-07-18 20:43:14 +02:00
# include "mifare.h"
2015-10-14 11:39:51 +02:00
# include "pcf7931.h"
2015-03-24 11:45:31 +01:00
# include "desfire.h"
2016-03-20 19:33:07 +01:00
# include "iso14443b.h"
2017-08-26 12:57:18 +02:00
# include "Standalone/standalone.h"
2018-02-13 15:45:15 +01:00
# include "flashmem.h"
2014-12-17 20:33:21 +01:00
2017-07-30 09:17:48 +02:00
extern const uint8_t OddByteParity [ 256 ] ;
2012-06-28 13:38:40 +00:00
extern int rsamples ; // = 0;
extern uint8_t trigger ;
2010-02-20 21:24:25 +00:00
2010-10-08 10:23:04 +00: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-20 21:24:25 +00: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-07 21:26:03 +02:00
void DbpStringEx ( uint32_t flags , char * str ) ;
2010-02-20 21:24:25 +00:00
void Dbprintf ( const char * fmt , . . . ) ;
2019-06-07 21:26:03 +02:00
void DbprintfEx ( uint32_t flags , const char * fmt , . . . ) ;
2012-09-18 13:53:17 +00:00
void Dbhexdump ( int len , uint8_t * d , bool bAsci ) ;
2010-02-20 21:24:25 +00:00
2015-02-03 07:21:57 +01: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 13:11:10 +01:00
// ADC Vref = 3300mV, (240k-10M):240k voltage divider, 140800 mV
# define MAX_ADC_HF_VOLTAGE_RDV40 140800
2015-02-03 07:21:57 +01: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 11:40:05 +01:00
uint16_t AvgAdc ( int ch ) ;
2011-06-10 13:35:10 +00:00
2017-01-25 00:33:03 +01:00
void print_result ( char * name , uint8_t * buf , size_t len ) ;
2019-04-07 11:36:24 +02:00
//void PrintToSendBuffer(void);
2010-02-20 21:24:25 +00:00
void ToSendStuffBit ( int b ) ;
void ToSendReset ( void ) ;
2019-05-20 04:28:34 -04:00
void ListenReaderField ( uint8_t limit ) ;
2010-02-20 21:24:25 +00:00
extern int ToSendMax ;
2010-02-20 22:51:00 +00:00
extern uint8_t ToSend [ ] ;
2010-02-20 21:24:25 +00:00
2019-04-06 01:00:54 +02:00
void StandAloneMode ( void ) ;
void printStandAloneModes ( void ) ;
2017-08-26 12:57:18 +02:00
2010-02-20 21:24:25 +00:00
/// lfops.h
2015-01-29 00:57:22 +01:00
extern uint8_t decimation ;
extern uint8_t bits_per_sample ;
extern bool averaging ;
2013-09-27 13:48:20 +00:00
void AcquireRawAdcSamples125k ( int divisor ) ;
2015-10-20 19:00:02 +02:00
void ModThenAcquireRawAdcSamples125k ( uint32_t delay_off , uint32_t period_0 , uint32_t period_1 , uint8_t * command ) ;
2010-02-20 21:24:25 +00:00
void ReadTItag ( void ) ;
2010-02-20 22:51:00 +00:00
void WriteTItag ( uint32_t idhi , uint32_t idlo , uint16_t crc ) ;
2015-10-20 19:00:02 +02:00
2010-02-20 21:24:25 +00:00
void AcquireTiType ( void ) ;
void AcquireRawBitsTI ( void ) ;
2019-05-24 09:11:30 -04:00
void SimulateTagLowFrequencyEx ( int period , int gap , bool ledcontrol , int numcycles ) ;
void SimulateTagLowFrequency ( int period , int gap , bool ledcontrol ) ;
2015-11-22 17:33:41 +01:00
void SimulateTagLowFrequencyBidir ( int divisor , int max_bitlen ) ;
2019-05-23 13:16:06 -04:00
2019-05-24 09:11:30 -04: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-23 13:16:06 -04:00
2019-05-24 09:11:30 -04: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 07:06:08 -04:00
2017-10-29 03:26:46 +01: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 11:20:10 +01:00
void CmdEM410xdemod ( int findone , uint32_t * high , uint64_t * low , int ledcontrol ) ;
2017-10-29 03:26:46 +01:00
void CmdIOdemodFSK ( int findone , uint32_t * high , uint32_t * low , int ledcontrol ) ;
2015-11-02 20:46:17 +01:00
void CopyIOtoT55x7 ( uint32_t hi , uint32_t lo ) ; // Clone an ioProx card to T5557/T5567
2013-02-28 17:04:23 +00:00
void CopyHIDtoT55x7 ( uint32_t hi2 , uint32_t hi , uint32_t lo , uint8_t longFMT ) ; // Clone an HID card to T5557/T5567
2015-11-22 17:33:41 +01:00
void CopyVikingtoT55xx ( uint32_t block1 , uint32_t block2 , uint8_t Q5 ) ;
2012-03-07 13:44:53 +00:00
void WriteEM410x ( uint32_t card , uint32_t id_hi , uint32_t id_lo ) ;
2015-10-27 21:47:21 +01: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
2019-07-23 09:50:28 +10:00
void T55xxResetRead ( uint8_t flags ) ;
//id T55xxWriteBlock(uint32_t data, uint8_t blockno, uint32_t pwd, uint8_t flags);
2019-05-13 13:23:53 +02:00
void T55xxWriteBlock ( uint8_t * data ) ;
2019-07-23 09:50:28 +10:00
// void T55xxWriteBlockExt(uint32_t data, uint8_t blockno, uint32_t pwd, uint8_t flags);
2019-07-23 23:43:30 +02:00
void T55xxReadBlock ( uint8_t page , bool pwd_mode , bool brute_mem , uint8_t block , uint32_t pwd , uint8_t downlink_mode ) ;
2019-07-27 09:36:16 +02:00
void T55xxWakeUp ( uint32_t pwd , uint8_t flags ) ;
2019-07-23 09:50:28 +10:00
void T55xx_ChkPwds ( uint8_t flags ) ;
2019-01-11 14:46:27 +01:00
2016-10-08 19:12:51 +02:00
void TurnReadLFOn ( uint32_t delay ) ;
2019-05-28 05:15:12 -04:00
2017-02-07 22:26:06 +01:00
void EM4xReadWord ( uint8_t addr , uint32_t pwd , uint8_t usepwd ) ;
2019-05-28 05:15:12 -04:00
void EM4xWriteWord ( uint8_t addr , uint32_t data , uint32_t pwd , uint8_t usepwd ) ;
2017-02-02 15:32:21 +01:00
void Cotag ( uint32_t arg0 ) ;
2019-07-27 21:15:43 +02:00
void setT55xxConfig ( uint8_t arg0 , t55xx_configurations_t * c ) ;
t55xx_configurations_t * getT55xxConfig ( void ) ;
2018-09-11 18:35:07 +02:00
void printT55xxConfig ( void ) ;
void loadT55xxConfig ( void ) ;
2010-02-20 21:24:25 +00:00
2016-08-04 21:51:26 +02:00
/// iso14443b.h
2016-04-27 11:21:29 +02:00
void SimulateIso14443bTag ( uint32_t pupi ) ;
2015-06-18 09:52:53 +02:00
void AcquireRawAdcSamplesIso14443b ( uint32_t parameter ) ;
2016-03-20 19:33:07 +01:00
void ReadSTMemoryIso14443b ( uint8_t numofblocks ) ;
2018-01-06 21:12:28 +01:00
void RAMFUNC SniffIso14443b ( void ) ;
2013-09-01 18:41:05 +00:00
void SendRawCommand14443B ( uint32_t , uint32_t , uint8_t , uint8_t [ ] ) ;
2019-04-18 12:43:35 +02:00
void SendRawCommand14443B_Ex ( PacketCommandNG * c ) ;
2017-01-25 00:33:03 +01:00
void ClearFpgaShiftingRegisters ( void ) ;
2010-02-20 21:24:25 +00:00
2016-08-04 21:51:26 +02:00
// iso14443a.h
2015-05-16 15:34:01 +02:00
void RAMFUNC SniffIso14443a ( uint8_t param ) ;
2019-04-18 12:43:35 +02:00
void ReaderIso14443a ( PacketCommandNG * c ) ;
2018-02-28 13:21:47 +01:00
2012-06-28 13:38:40 +00:00
// Also used in iclass.c
2016-05-08 18:52:19 +02: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-06 20:21:03 +02:00
void GetParity ( const uint8_t * pbtCmd , uint16_t len , uint8_t * par ) ;
2012-12-04 23:39:18 +00:00
void iso14a_set_trigger ( bool enable ) ;
2017-03-01 21:51:23 +01:00
// also used in emv
2019-03-15 21:04:25 +01:00
//bool prepare_allocated_tag_modulation(tag_response_info_t *response_info);
//int GetIso14443aCommandFromReader(uint8_t *received, uint8_t *parity, int *len);
2015-02-07 20:49:40 +01:00
2016-08-04 21:51:26 +02:00
// epa.h
2019-04-18 12:43:35 +02:00
void EPA_PACE_Collect_Nonce ( PacketCommandNG * c ) ;
void EPA_PACE_Replay ( PacketCommandNG * c ) ;
2012-08-28 21:39:50 +00:00
2011-06-17 18:39:54 +00:00
// mifarecmd.h
2019-05-28 13:20:56 -04:00
void MifareReadBlock ( uint8_t blockNo , uint8_t keyType , uint8_t * datain ) ;
2015-03-24 11:45:31 +01:00
void MifareUReadBlock ( uint8_t arg0 , uint8_t arg1 , uint8_t * datain ) ;
2019-04-07 12:30:49 +02:00
void MifareUC_Auth ( uint8_t arg0 , uint8_t * keybytes ) ;
2015-05-05 00:34:20 +02:00
void MifareUReadCard ( uint8_t arg0 , uint16_t arg1 , uint8_t arg2 , uint8_t * datain ) ;
2019-05-13 12:49:41 +02: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-27 23:23:46 +02:00
//void MifareUWriteBlockCompat(uint8_t arg0,uint8_t *datain);
void MifareUWriteBlock ( uint8_t arg0 , uint8_t arg1 , uint8_t * datain ) ;
2011-06-07 12:35:52 +00:00
void MifareNested ( uint32_t arg0 , uint32_t arg1 , uint32_t arg2 , uint8_t * datain ) ;
2015-11-27 16:24:00 +01:00
void MifareAcquireEncryptedNonces ( uint32_t arg0 , uint32_t arg1 , uint32_t flags , uint8_t * datain ) ;
2019-05-13 13:31:11 +02:00
void MifareAcquireNonces ( uint32_t arg0 , uint32_t flags ) ;
2019-05-13 12:25:11 +02:00
void MifareChkKeys ( uint8_t * datain ) ;
2017-10-05 16:00:56 +02:00
void MifareChkKeys_fast ( uint32_t arg0 , uint32_t arg1 , uint32_t arg2 , uint8_t * datain ) ;
2019-05-27 07:46:27 -04:00
2019-05-13 12:30:27 +02:00
void MifareEMemClr ( void ) ;
2019-05-27 07:46:27 -04: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 03:03:24 -04:00
int MifareECardLoad ( uint32_t arg0 , uint32_t arg1 ) ;
2019-05-27 07:46:27 -04:00
2015-11-09 21:46:15 +01: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-26 21:32:58 +01:00
void MifareCIdent ( ) ; // is "magic chinese" card?
2019-05-27 07:46:27 -04:00
2019-05-15 06:52:22 -04:00
void MifareSetMod ( uint8_t * datain ) ;
2015-03-30 16:24:03 +02:00
void MifareUSetPwd ( uint8_t arg0 , uint8_t * datain ) ;
2015-11-09 21:46:15 +01:00
void OnSuccessMagic ( ) ;
void OnErrorMagic ( uint8_t reason ) ;
2015-04-24 18:41:49 +02:00
2016-08-04 21:51:26 +02:00
int32_t dist_nt ( uint32_t nt1 , uint32_t nt2 ) ;
2019-03-10 00:00:59 +01:00
void ReaderMifare ( bool first_try , uint8_t block , uint8_t keytype ) ;
2018-01-18 14:11:22 +01:00
//void RAMFUNC SniffMifare(uint8_t param);
2016-08-04 21:51:26 +02:00
2014-12-31 11:35:43 +01:00
//desfire
2019-03-10 00:00:59 +01:00
void Mifare_DES_Auth1 ( uint8_t arg0 , uint8_t * datain ) ;
2019-03-09 08:59:13 +01:00
void Mifare_DES_Auth2 ( uint32_t arg0 , uint8_t * datain ) ;
2014-12-31 11:35:43 +01:00
2014-09-11 23:23:46 +02:00
// mifaredesfire.h
2016-08-04 21:51:26 +02:00
bool InitDesfireCard ( ) ;
2019-03-10 00:00:59 +01:00
void MifareSendCommand ( uint8_t arg0 , uint8_t arg1 , uint8_t * datain ) ;
2016-08-04 21:51:26 +02:00
void MifareDesfireGetInformation ( ) ;
2019-03-10 00:00:59 +01: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-04 21:51:26 +02:00
int DesfireAPDU ( uint8_t * cmd , size_t cmd_len , uint8_t * dataout ) ;
2019-03-10 00:00:59 +01:00
size_t CreateAPDU ( uint8_t * datain , size_t len , uint8_t * dataout ) ;
2016-08-04 21:51:26 +02:00
void OnSuccess ( ) ;
void OnError ( uint8_t reason ) ;
2014-10-06 19:42:50 +02:00
2015-03-24 11:45:31 +01:00
// desfire_crypto.h
2019-03-10 00:00:59 +01: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-11 23:23:46 +02:00
2017-02-23 00:03:10 +01:00
// iso15693.h
2010-10-19 14:25:17 +00:00
void RecordRawAdcSamplesIso15693 ( void ) ;
2010-02-20 21:24:25 +00:00
void AcquireRawAdcSamplesIso15693 ( void ) ;
2019-03-09 20:34:41 +01: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 14:25:17 +00:00
void BruteforceIso15693Afi ( uint32_t speed ) ; // find an AFI of a tag - atrox
2019-03-10 00:00:59 +01:00
void DirectTag15693Command ( uint32_t datalen , uint32_t speed , uint32_t recv , uint8_t * data ) ; // send arbitrary commands from CLI - atrox
2017-08-31 13:24:12 +02:00
void Iso15693InitReader ( void ) ;
2010-02-20 21:24:25 +00:00
2017-02-23 00:03:10 +01:00
// iclass.h
2017-08-26 12:57:18 +02:00
void RAMFUNC SniffIClass ( void ) ;
2014-04-17 09:53:54 +02:00
void SimulateIClass ( uint32_t arg0 , uint32_t arg1 , uint32_t arg2 , uint8_t * datain ) ;
2012-06-28 13:38:40 +00:00
void ReaderIClass ( uint8_t arg0 ) ;
2019-04-06 20:21:03 +02:00
void ReaderIClass_Replay ( uint8_t arg0 , uint8_t * mac ) ;
void iClass_Authentication ( uint8_t * mac ) ;
2017-12-21 10:13:40 +01:00
void iClass_Authentication_fast ( uint64_t arg0 , uint64_t arg1 , uint8_t * datain ) ;
2019-04-06 20:21:03 +02: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-07 23:00:46 +02:00
void iClass_Dump ( uint8_t blockno , uint8_t numblks ) ;
void iClass_Clone ( uint8_t startblock , uint8_t endblock , uint8_t * data ) ;
2019-04-06 20:21:03 +02:00
void iClass_ReadCheck ( uint8_t blockno , uint8_t keytype ) ;
2011-05-18 12:33:32 +00:00
2012-12-05 16:14:10 +00:00
// cmd.h
2019-04-22 22:58:45 +02: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-05 16:14:10 +00:00
2016-08-04 21:51:26 +02:00
// util.h
2019-03-12 13:15:39 +01:00
void HfSniff ( int , int ) ;
2016-08-04 21:51:26 +02:00
2017-10-20 20:27:44 +02:00
//felica.c
2019-04-18 12:43:35 +02:00
void felica_sendraw ( PacketCommandNG * c ) ;
2019-04-06 01:00:54 +02:00
void felica_sniff ( uint32_t samplesToSkip , uint32_t triggersToSkip ) ;
void felica_sim_lite ( uint64_t uid ) ;
void felica_dump_lite_s ( ) ;
2017-10-20 20:27:44 +02:00
2018-02-13 15:45:15 +01:00
2017-01-25 00:33:03 +01:00
# ifdef __cplusplus
}
# endif
2010-02-20 21:24:25 +00:00
# endif